learn the python the hard way习题11~17总结

关于 input()

格式: input("prompt")
功能:从 CLI 获取 User 的一个输入,显示 promt 的内容,并且返回一个 string 类型的数值
其他:如果想要读取 User 的输入进行数学运算,可以使用x= int(input()),或者float(input())

脚本,模块,解包

脚本:程序
将模块引入脚本:from sys import argv
解包:script, first, second, third = argv

将 argv 中的东西取出,解包,将所有的参数依次赋值给左边的这些变量。

与文件有关的函数

  • open:打开文件,返回一个文件对象(file object)
  • close: 关闭文件
  • read: 读取文件,返回文件的整个内容
  • readline:只读取文本文件中的一行
  • truncate:清空文件
  • write('stuff'):将”stuff"写入文件
  • seek(0):将读写位置移动到文件开头

在 CLI中的操作

echo创建含有内容的文件

用法:echo "This is a test file.">test.txt
可以通过这个方法创建一个名字叫 test.txt,内容为“This is a test file"的文件。

pydoc查看说明文档

用法:pydoc input 
可以通过这个在命令行中查看 input 的介绍,按 q 结束查看。

猜你喜欢

转载自www.cnblogs.com/FBsharl/p/10158446.html