小智 8
正如其他人所说,这是Python字符串格式化/插值运算符.它基本上相当于C中的sprintf,例如:
a = "%d bottles of %s on the wall" % (10, "beer")
相当于像
a = sprintf("%d bottles of %s on the wall", 10, "beer");
在C.每个都有a设置的结果"10 bottles of beer on the wall"
但请注意,在Python 3.0中不推荐使用此语法; 它的替换看起来像
a = "{0} bottles of {1} on the wall".format(10, "beer")
这是有效的,因为任何字符串文字都会被Python自动转换为str对象.
| 归档时间: |
|
| 查看次数: |
710 次 |
| 最近记录: |