I want to know that why adding a trailing comma after a variable name (in this case a string) makes it a tuple. i.e.
>>> abc = \'mystr
When you see a comma after a single value, that value is interpreted as the datatype 'tuple'.
Here is a little something I've learned through experience that may apply to some of you:
If you're a musician, the word tuple may be confusing, since the words tuple and triple are used to describe groupings of notes that are used within a certain type of time signature that they are not strictly compatible with. For example a grouping of two eighth notes played as if the time signature were 4/4 (straight feel) when the time signature is 6/8 (triplet feel). Or vice versa a triplet played in 4/4 time. This leads the novice programmer to perhaps interpret a tuple as a pair of values.
This isn't the same kind of tuple as you see in programming. These tuples are an immutable (un-alterable once assigned) sequence data type that can hold any number of values but can be considered to be transferred together as if they were all enclosed between to parentheses, or in other words, a tuple of parentheses.
You can't add or delete stuff from a tuple once it is assigned, so it is usually used to pack and unpack variables. I use it frequently to return multiple values from a function:
def somefunction_foo(some_data_file):
map1 = dict()
map2 = dict()
map3 = dict()
with open(datafile, 'r') as file: # auto-close the file after this block
for row in file:
pass
# don't actually pass, but
# fill each map with specific data from the same file
return map1, map2, map3 # I'm returning a tuple, but without parenthesis