print中的逗号“,”打印出来相当于空格

一、print中的逗号“,”打印出来相当于空格

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

>>> print('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')效果一样。

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

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

二、print('%f' %(2.1))

%f 格式化定点数,可指定精度(默认小数点后面保留6位)
%e 科学计数法计数
%g 根据值的大小采用%e或%f,但最多保留6位有效数字。

猜你喜欢

转载自blog.csdn.net/zio123/article/details/79186531