Class 1:- Python and Object Oriented Programing

I have a White cat and also my neighbor has a Black cat. So in the OOP paradigm the cat is blueprint and from using that blueprint we can create several cat objects with different attributes specific to that object. Like here, they both have four legs but they have different color and size. So, let’s code:-

class Cat():
  pass  # Cat class created and pass is mentioned as it is empty class now.

my_cat = Cat()  #Two different cat object created from the Cat blueprint

Neighbor_cat = Cat()

One important aspect is that these two objects has different location in memory. We can check this easily by using the below code:-

class Cat():
  pass

my_cat = Cat()

Neighbor_cat = Cat()

print(my_cat)
print(Neighbor_cat)

The out put for my case is:-

<__main__.Cat object at 0x7f9960209c40>
<__main__.Cat object at 0x7f99601ee0a0>

Now assign attributes to my cat and my bad neighbor’s cat. Mine is white and neighbor’s is black.

class Cat():
  pass

my_cat = Cat()

Neighbor_cat = Cat()

my_cat.color = 'white'
Neighbor_cat.color = 'Black'

# These above two object specific to each objects

print(my_cat.color)
print(Neighbor_cat.color)

output:-
white
Black

In the above case the two attributes are specific to the object, not to the class.