Chinaunix

标题: {0:30^30} [打印本页]

作者: tomer    时间: 2014-11-14 10:26
标题: {0:30^30}
print("decimal   hex   chr   {0:^30}".format("name"))
decimal   hex   chr                name

{0:^30}是什么意思?
作者: whitelotus19    时间: 2014-11-14 11:06
  1. >>> print("decimal   hex   chr   {0:^30}".format("name"))
  2. decimal   hex   chr                name            
  3. >>> print("decimal   hex   chr   {0:^30}".format("name"),'test')
  4. decimal   hex   chr                name              test
  5. >>> print("decimal   hex   chr   {0:<30}".format("name"),'test')
  6. decimal   hex   chr   name                           test
  7. >>> print("decimal   hex   chr   {0:>30}".format("name"),'test')
  8. decimal   hex   chr                             name test
  9. >>> print("decimal   hex   chr   {1:>30}".format("name","abc"),'test')
  10. decimal   hex   chr                              abc test
  11. >>>
复制代码

作者: tomer    时间: 2014-11-14 12:45
回复 2# whitelotus19


    "decimal   hex   chr   {0:^30}".format("name")
    {0:^30}<--0代表的是name;那么后面的^30是什么意思??
作者: whitelotus19    时间: 2014-11-14 14:56
居中对齐,宽度30
作者: tomer    时间: 2014-11-14 16:34
回复 4# whitelotus19


    谢谢,明白了。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2