美文网首页Python
Python:输出

Python:输出

作者: h266094 | 来源:发表于2017-10-15 15:38 被阅读0次

用print(),在括号中加上字符串,就可以向屏幕上输出指定的文字。比如输出'hello, world',用代码实现如下:

>>>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-explain

print()也可以打印整数,或者计算结果:

print(300)
300
print(100 + 200)
300

因此,我们可以把计算100 + 200的结果打印得更漂亮一点:

print('100 + 200 =', 100 + 200)100 + 200 = 300

注意,对于100 + 200,Python解释器自动计算出结果300,但是,'100 + 200 ='是字符串而非数学公式,Python把它视为字符串。

相关文章

网友评论

    本文标题:Python:输出

    本文链接:https://www.haomeiwen.com/subject/ghkcuxtx.html