Python的基本输入输出函数

来源:互联网 发布:2016奥运男篮冠军数据 编辑:程序博客网 时间:2024/05/16 11:06

一 接受输入的input函数

举例如下:
>>> input('input your name')input your name cakin' cakin'>>> name = input('input your name:')input your name:cakin>>> print(name)cakin>>> year = input('The year:')The year:2017>>> print(year)2017>>> year+1Traceback (most recent call last):  File "<pyshell#5>", line 1, in <module>    year+1TypeError: must be str, not int>>> int(year)+12018>>> 
 
二 输出内容的print函数
举例如下:
>>> a = 0>>> print(a)0>>> b = 1>>> print(a+b)1>>> print(b)1>>> a = 'hello'>>> print(a)hello>>> l = [1,2,3]>>> print(l)[1, 2, 3]>>> t = (4,5,6)>>> print(t)(4, 5, 6)>>> print(l,t)[1, 2, 3] (4, 5, 6)>>> print(l,'\n',t)[1, 2, 3]  (4, 5, 6)>>> for i in t:print(i)456