Example:
regular_string = "%s %s" % ("foo", "bar")
result = {}
result["somekey"] = regular_string,
print result["somekey"]
# ('foo bar',)
Why result["somekey"]
tuple now not string?
因为逗号在行尾。
When you write
result["somekey"] = regular_string,
Python reads
result["somekey"] = (regular_string,)
(x,)
is the syntax for a tuple with a single element. Parentheses are assumed. And you really end up putting a tuple, instead of a string there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.