First rule of Python is - Everything in Python is an object

  • Everything in Python is an object, and almost everything has attributes and methods.
  • dir(object) to display the attributes and methods
  • Everything can be assigned to a variable or passed as an argument to a function.
  • Everything in Python has: an identity (id) and a value (mutable or immutable)

lists2

lists2

lists2


>>> id(a)
26165592
>>> 
>>> id(b)
26165592
>>> 
>>> a = 2
>>> 
>>> id(a)
26165568
>>> id(b)
26165592
>>>
>>> a = 10
>>> a -= 9
>>> a
1
>>> id(a)
26165592