this list is awesome. made my morning.
anyone know why this works in python
lst=[]
lst+=2, # note , in the end
print(lst) #[2]anyone know why this works in python
lst=[]
lst+=2, # note , in the end
print(lst) #[2] [] + (2,)
is a TypeError: can only concatenate list (not "tuple") to list
but L = []
L += (2,)
is totally cool.In the end, it makes sense because I can't tell you if []+() should be a tuple or a list, and even if I did, I might have a different answer for ()+[]; whereas L+=bla looks like the type of L should not change.
lst += (2,) () # Makes a zero-tuple. The parens are required.
2, # Makes a one-tuple.
(2,) # Makes a one-tuple. The parens are optional.
[2] # Makes a list of size one.
[(2)] # Also makes a list of size one.
[2,] # Also makes a list of size one.
f(x, y) # Call a function with two arguments.
f((x, y)) # Make a 2-tuple and call a function with one argument.BTW, kind of a tangent, I've always assumed (but not checked) that every "()" literal evaluates to one singleton zero-tuple, do you know if that's true?
Also, it used to be true that ``frozenset() is frozenset()``, but that was lost in the war on singletons and global state.