2017-06-09 100 views
2

下面是一个简单的例子如何在字符串中的蟒蛇插入变量值

amount1 = input("Insert your value: ") 
amount2 = input("Insert your value: ") 
print "Your first value is", amount1, "your second value is", amount2 

这是好的,但我想知道是否有包括无连接字符串中的变量的另一种方法或逗号。

这可能吗?

+0

[大多数Pythonic方式来连接字符串]可能的重复(https://stackoverflow.com/questions/2133571/most-pythonic-way-to-concatenate-strings) – zwer

回答

1

你也可以使用老的那种%格式:

print "this is a test %03d which goes on" % 10 

本页面https://pyformat.info/具有相当不错的比较!