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
 
 
 
发布了4085 篇原创文章 · 获赞 543 · 访问量 301万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览