为什么后面double %%转成single %
Why is later double %% converted to single %
l='a'
r='%sbb%%'%l
print(r)
我期望输出 abb%%
,但实际输出是 abb%
。
有人可以解释为什么吗?
百分号 %
是一个特殊的元字符。我在下面描述了一些例子:
输入:
print("Hello %s %s. Your current balance is %.2f" % ("John", "Doe", 53.4423123123))
print("Hello, %s!" % "Bob")
print("%s is %d years old." % ("Sarah", 43))
print("Ian scored %.0f%s on the quiz." % (98.7337, "%"))
lyst = [1, 2, 3]
print("id(lyst) == %d" % id(lyst))
print("id(lyst) in hexadecimal format is %x" % id(lyst))
输出:
Hello John Doe. Your current balance is 53.44
Hello, Bob!
Sarah is 43 years old.
Ian scored 99% on the quiz.
id(lyst) == 58322152
id(lyst) in hexadecimal format is 379ece8
备注:
+------+----------------------------------------------+
| %s | String |
| %d | Integer |
| %f | Floating point number |
| %.2f | float with 2 digits to the right of the dot. |
| %.4f | float with 4 digits to the right of the dot. |
| %x | Integers in hex representation |
+------+----------------------------------------------+
l='a'
r='%sbb%%'%l
print(r)
我期望输出 abb%%
,但实际输出是 abb%
。
有人可以解释为什么吗?
百分号 %
是一个特殊的元字符。我在下面描述了一些例子:
输入:
print("Hello %s %s. Your current balance is %.2f" % ("John", "Doe", 53.4423123123))
print("Hello, %s!" % "Bob")
print("%s is %d years old." % ("Sarah", 43))
print("Ian scored %.0f%s on the quiz." % (98.7337, "%"))
lyst = [1, 2, 3]
print("id(lyst) == %d" % id(lyst))
print("id(lyst) in hexadecimal format is %x" % id(lyst))
输出:
Hello John Doe. Your current balance is 53.44
Hello, Bob!
Sarah is 43 years old.
Ian scored 99% on the quiz.
id(lyst) == 58322152
id(lyst) in hexadecimal format is 379ece8
备注:
+------+----------------------------------------------+
| %s | String |
| %d | Integer |
| %f | Floating point number |
| %.2f | float with 2 digits to the right of the dot. |
| %.4f | float with 4 digits to the right of the dot. |
| %x | Integers in hex representation |
+------+----------------------------------------------+