“()” is a ‘tuple’ constructor.
i.e. it effectively constructs a read-only list from the parameters provided. If you “print” a tuple (or list), it will show you it’s contents essentially in the form used to create it in the first place. Try;
a=(1,2,3,4,5)
print a
print a[1]
a[1]=9
The last line will error as being a tuple, it’s read-only. If you try;
a=[1,2,3,4,5]
print a
print a[1]
a[1]=9
The results will be similar except the last line won’t error, “” is a list constructor. (lists are read/write)
To really bend your mind a little “(1)” will not generate a tuple as it thinks it’s an arithmetic expression, i.e. a “1” in brackets … “(1,2)” will generate a tuple because it’s obviously not an arithmetic expression, so if you want a tuple containing a single numeric entry, you need to write “(1,)”. An example of when this is useful;
#Add an additional digit to a tuple;
a=(1,2,3)
a+4 # will not work
a+(4) # will not work
a+(4,) , will work and yields (1,2,3,4)
Exercise, work out why / how this works;
a=('a','b','c')
"-".join(a)
MP Loves Python … 