赞
踩
输入和输出
输出
1、输出字符串
用print加上字符串,就可以向屏幕上输出指定的文字。比如输出'hello, world',用代码实现如下:>>>
'hello, world'
print语句也可以跟上多个字符串,用逗号“,”隔开,就可以连成一串输出:>>> print 'The quick brown fox', 'jumps over', 'the lazy dog'
The quick brown fox jumps over the lazy dog
注:print会依次打印每个字符串,遇到逗号“,”会输出一个空格(),因此,输出的字符串是这样拼起来的
>>> print 'The quick brown fox', 'jumps over', 'the lazy dog'
The quick brown foxjumps overthe lazy dog
2、打印整数或计算
print也可以打印整数,或者计算结果:>>> print 500
500
>>> print 300 + 200
500
因此,我们可以把计算100 + 200的结果打印得更漂亮一点:>>> print '100 + 200 =', 100 + 200
100 + 200 = 300
注&
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。