打印输出
print("Hello World")
input
用户手动输入
name = input("请输入名字:")
print(name, type(name))
Jack <class 'str'>
open
打开文档
file = '1.txt'
modes = ["r", "r+", "w", "w+", "a", "a+"]
mode = modes[3]
with open(file, mode) as f:
f.read()
open共有6种模式:r、r+、w、w+、a、a+
- r:只读,流位于开头,若无该文件则报错FileNotFoundError
- r+:读写,流位于开头,若无该文件则报错FileNotFoundError
- w:只写,流位于开头,若无该文件则自动创建
- w+:读写,流位于开头,若无该文件则自动创建
- a:只写,流位于结尾,若无该文件则自动创建
- a+:读写,流位于结尾,若无该文件则自动创建
源码
https://github.com/xiligey/Notes/blob/master/Python/basic/io/built-in_io.py