基本输入输出
input
python官方文档对input函数的说明
input([prompt])
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.
注意:prompt参数可以为空
用Python进行程序设计,输入是通过input( )函数来实现的
x = input(‘提示:’)该函数返回输入的对象。可输入数字、字符串和其它任意类型对象。
在Python 3.x中,input()函数用来接收用户的键盘输入,不论用户输入数据时使用什么界定符,input()函数的返回结果都是字符串,需要将其转换为相应的类型再处理。
# input实例
s = input('--> ')
--> Monty Python's Flying Circus
s
"Monty Python's Flying Circus"
基本输出函数 print
作用:将一系列的值以字符串形式输出到标准输出设备上,默认为终端
格式
print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
官方解释Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.
All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.
The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Since printed arguments are converted to text strings, print() cannot be used with binary mode file objects. For these, use file.write(…) instead.
Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.在python初级学习阶段
print函数只需要掌握这种语法格式:print(*objects, ········,sep=’ ‘, end=’\n’)
print函数里面的关键字参数为:sep 两个值之间的分隔符 默认为一个空格
end 输出完毕后在流末尾自动追加一个字符,默认为换行符“\n”
print(0, 1, 2, 3, 4, 5) ------> 0 1 2 3 4 5
print(0, 1, 0, 2, 0, 3,sep="! ") ------> 0! 1! 0! 2! 0! 3
print(0, 0, 1, 1, 2, 2,sep = "% ",end = "\n\n\n\n\n\n" ) -----> 0% 0% 1% 1% 2% 2 (\n 换行符,表示换行 即 回车)
print(0, 1, 0, 2, 0, 3,end = " ")------> end = "" 表示不换行
print("sss") ---------> 0 1 0 2 0 3 sss