- In Python, a variable is just a label assigned to a memory that contains a value.
- A variable can point to the value of any data type.
- A value not assigned to a variable (label) is garbage collected.
a = 1
print(a)
# => 1Variable (label) points to the new value and old value unless pointed by another variable is garbage collected.
a = 1
a = 10
print(a)
# => 10b, c = 2, 3
print( b, c )
# => 2 3These ariables (labels) point to the same value.
a = b = c = 1
print('a = b = c = 1 => ', a, b, c)
# => a = b = c = 1 => 1 1 1- The
delkeyword removes the binding between variable name and the value by removing the variable (label). - The value will be garbage collected unless pointed by another vaiable.
https://stackoverflow.com/questions/21053380/what-does-del-do-exactly)
a = b = 1
del b
print(b)
# => NameError: name 'b' is not defined
print(a)
# => 1- Generally use lowercase ASCII letters.
- You can use camelCase or snake_case syntax.
- Use
ALL_UPPERCASEletters for global constants (fixed values).- Constants do not exist in Python -> https://stackoverflow.com/a/2682752/2790983
- Use
_prefix for_privateor_INTERNALvariables and constants. - Do not start a variable with a digit.