A class is a blueprint for the creation of different objects. When the objects get created to form the class, they no longer depend on the class attribute. Also, the class has no control over the attributes of the instances created.
Syntax of Object:
object_name = class_name ( arguments )
Example of Object:
s = student ( )
The code is defining a class called user with one class attribute, course with value Java. The user.__dict__ is a dictionary that contains the class and its attributes and methods. It will print the class attribute course in the form of dictionary.
class user: course = 'Java' o = user() print(user.__dict__) print(user.course) # Print Class attribute print(o.__dict__) print(o.course) o.course = "C++" print(o.__dict__) print(o.course) o2 = user() print(o2.course)To download raw file Click Here
{'__module__': '__main__', 'course': 'Java', '__dict__': <attribute '__dict__' of 'user' objects>, '__weakref__': <attribute '__weakref__' of 'user' objects>, '__doc__': None} Java {} Java {'course': 'C++'} C++ Java
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions