-1
我认为%
(模)从部门返回余留,但看到这段代码,现在我很困惑。'string%variables`中的%运算符是什么?
下面的代码:
prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15
}
for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
我的问题是关于具体的最后3行。 %
在这里做什么?
这是一个格式说明符:有关一些解释和示例,请参阅https://docs.python.org/2/library/stdtypes.html#string-formatting-operations –
请参阅:https:/ /pyformat.info/ – andpei