This code defines a class called Student with class attributes name and age and a class method printall(). The printall() method is defined within the class and it prints the values of class attributes name and age.
# Class Methods class Student: name = "Tutor Joes" age = 25 def printall(): print("Name : ", Student.name) print("Age : ", Student.age) Student.printall() print(Student.__dict__) print(getattr(Student, "printall")) getattr(Student, "printall")() Student.__dict__['printall']()To download raw file Click Here
Name : Tutor Joes Age : 25 {'__module__': '__main__', 'name': 'Tutor Joes', 'age': 25, 'printall': <function Student.printall at 0x000001F08DD5B5E0>, '__dict__': <attribute '__dict__' of 'Student' objects>>, '__weakref__':, '__doc__': None} Name : Tutor Joes Age : 25 Name : Tutor Joes Age : 25
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions