Input
x = raw_input()
y = raw_input("Name?")
#这句话会用 “Name?” 提示用户
z = raw_input("> ")Import
from sys import argv
script, first, second, third = argv
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
Read and Write file
txt = open("d:\text.txt")
#txt = open("d:\text.txt", 'w')
print txt.read()
txt.close()close – 关闭文件。
read – 读取文件内容。你可以把结果赋给一个变量。
readline – 读取文本文件中的一行。
truncate – 清空文件,请小心使用该命令。
write(stuff) – 将stuff写入文件。
本文介绍了Python中基本的输入输出操作,包括从用户获取输入、导入模块参数、读取和写入文件等常见应用场景,并解释了相关命令的作用。
615

被折叠的 条评论
为什么被折叠?



