python实例学习
程序员文章站
2022-04-22 11:33:20
1.Python ASCII码与字符相互转换#!/usr/bin/python3# _*_ coding: UTF-8 _*_str=input("Please input a char:")num=input("Please input a ASCII:")print('char ASCII:',ord(str))print('ASCII char:',chr(num))执行以上代码输出结果为:Please input a char:'w'Please input a ASCII...
1.Python ASCII码与字符相互转换
#!/usr/bin/python3
# _*_ coding: UTF-8 _*_
str=input("Please input a char:")
num=input("Please input a ASCII:")
print('char ASCII:',ord(str))
print('ASCII char:',chr(num))
执行以上代码输出结果为:
Please input a char:'w'
Please input a ASCII:12
('char ASCII:', 119)
('ASCII char:', '\x0c')
2.Python 文件 IO
以下代码演示了Python基本的文件操作,包括 open,read,write:
#Write a file
with open("test.txt","wt") as out_file:
out_file.write("a b c d e")
#Read a file
with open("test.txt","rt") as in_file:
text=in_file.read()
print(text)
执行以上代码输出结果为:
a b c d e
本文地址:https://blog.csdn.net/baidu_34971492/article/details/109643652