[Solved] difference between these 3 types of variable assignments


  • First one is three-element tuple.
  • Second one is some string.
  • Third one is same three-element tuple, since in this context parentheses are redundant.

Small code snippet will be enough to prove it:

g1 = (3, 4, 5)
g2 = "(3, 4, 5)"
g3 = 3, 4, 5
type(g1)  # <type 'tuple'>
type(g2)  # <type 'str'>
type(g3)  # <type 'tuple'>
g1 == g3  # True
g1 == g2  # False
g2 == g3  # False
g1[0]  # 3, first element of tuple, type: int
g2[0]  # "(", first char of string, type: str

To sum up, string representation of object and object properties are two different concepts. There may be multiple objects with same string representation but different behavior.

1

solved difference between these 3 types of variable assignments