现在学到了如何将十进制转换为其他进制,和字符与ASCII码之间的转换。
还有文件的读写。
dec = 12
print(bin(dec)) #二进制
print(oct(dec)) #八进制
print(hex(dec)) #十六进制
c = 'a'
a = '10'
print(ord(c)) #字符 -> ASCII码
print(chr(a)) #ASCII码 -> 字符
文件的读写:
# 写文件
with open("out", "wt") as out_file:
out_file.write("该文本会写入到文件中\n看到我了吧!")
# Read a file
with open("in", "rt") as in_file:
text = in_file.read()
print(text)