Python的基本输入输出函数

一 接受输入的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+1
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    year+1
TypeError: must be str, not int
>>> int(year)+1
2018
>>> 
 
二 输出内容的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)
	
4
5
6
 
 
 

猜你喜欢

转载自cakin24.iteye.com/blog/2381280