关于打印输出的一些方法

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,使用’:’更有效地控制输出格式

       image

       image

posted on 2017-07-14 16:36  freshair_cn  阅读(353)  评论(0编辑  收藏  举报

导航