输入与输出:
输出print
print(self, *args, sep=' ', end='\n', file=None)
file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream. 在Python3中print需加括号,可以直接输出字符串、变量(数值,布尔,列表,字典...),变量之间加逗号输出空格,结尾默认换行 例:
>>> print(1)1>>> print(1+2)3>>> print("1 + 2 =",1+2)1 + 2 = 3
输入input
input() 内置函数从标准输入读入一行文本,默认的标准输入是键盘,input返回的是一个字符串
例子:
>>> num=input("please input a int number")please input a int number1>>> print(int(num)+2)3
上述例子中的num是一个字符串类型的值,所以在做加法运算的时候要强制转换为int类型