码迷,mamicode.com
首页 > 其他好文 > 详细

str.format()

时间:2016-10-16 14:15:07      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:

Format strings contain “replacement fields” surrounded by curly braces {}

"First, thou shalt count to {0}"  # References first positional argument
"Bring me a {}"                   # Implicitly references the first positional argument
"From {} to {}"                   # Same as "From {0} to {1}"
"My quest is {name}"              # References keyword argument ‘name‘
"Weight in tons {0.weight}"       # ‘weight‘ attribute of first positional arg
"Units destroyed: {players[0]}"   # First element of keyword argument ‘players‘.

Two conversion flags are currently supported: ‘!s‘ which calls str() on the value, and ‘!r‘ which calls repr().

str.format()

标签:

原文地址:http://www.cnblogs.com/AngryZe/p/5966459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!