tags:

views:

433

answers:

2

Example:

regular_string = "%s %s" % ("foo", "bar")

result = {}
result["somekey"] = regular_string,

print result["somekey"]
# ('foo bar',)

Why result["somekey"] tuple now not string?

+13  A: 

Because of comma at the end of the line.

Jiri
+1. Commas, not parentheses, make tuples.
RichieHindle
Ah, missed comma.. Thanks
zdmytriv
+6  A: 

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.

Stefan Kanev