Random Remarks Example in python 1

Random Remarks Example in python

>>> class Warehouse:
        purpose = 'storage'
        region = 'west'

>>> w1 = Warehouse()
>>> print(w1.purpose, w1.region)
storage west
>>> w2 = Warehouse()
>>> w2.region = 'east'
>>> print(w2.purpose, w2.region)
storage east

Here is what the above code is Doing:
1. We create a class named Warehouse.
2. We assign the class attribute purpose to the string ‘storage’.
3. We assign the class attribute region to the string ‘west’.
4. We create an instance of the class named w1.
5. We print the value of the instance attribute purpose on w1, which is ‘storage’.
6. We print the value of the instance attribute region on w1, which is ‘west’.
7. We create another instance of the class named w2.
8. We assign the instance attribute region on w2 to the string ‘east’.
9. We print the value of the instance attribute purpose on w2, which is ‘storage’.
10. We print the value of the instance attribute region on w2, which is ‘east’.

Similar Posts