您好,欢迎访问一九零五行业门户网

打印结果的几种方法展示

1,str()和repr()
       str()目的是可读性,repr()目的是使结果清晰、无歧义
      两者没有多大的区别
2,建议使用以下.format()的格式打印:
       print (‘a is {} and b is {}’.format(‘a’, ‘b’))
3,可以在大括号内使用数字控制输出位置:
       print (‘a is {1} and b is {0}’.format(‘a’, ‘b’))
4,输出格式控制,ascii()用‘!a’,str()用’!s’,repr()用’!r‘:
       import math
       print (‘the value of pi is {!r}’.format(math.pi))
5,使用’:’更有效地控制输出格式
以上就是打印结果的几种方法展示的详细内容。
其它类似信息

推荐信息