python中的4种常用的print方式

python中的4种常用的print方式

>>> str=[1,2,3,4,5]   #定义一个列表变量

>>> print 'str=%s' % str   #字符串格式化(%占位操作符)
str=[1, 2, 3, 4, 5]
>>> print 'str={}'.format(str)  #字符串处理函数str.format(),用{}和.代替%
str=[1, 2, 3, 4, 5]
>>> print 'str=',str     #采用逗号+变量名的形式打印
str= [1, 2, 3, 4, 5]
>>> str               #直接打印
[1, 2, 3, 4, 5]

猜你喜欢

转载自blog.csdn.net/qq646748739/article/details/78323836
今日推荐