9 | Classes & Objects | Python for Complete Beginners

print(’Hello from ’) # Creating Class class MyClass1: # attributes (data and functions) pass class MyClass: a = 10 def func1(self): print(’Hello’) # Creating Objects # to access attributes of a class obj = MyClass() () print(obj.a) # we can create multiple objects from a class obj1 = MyClass() obj2 = MyClass() print(obj1.a) print(obj2.a) obj1.a = 20 obj2.a = 30 print(obj1.a) print(obj2.a) # Python is Object Oriented prog language # Classes and Objects # Class is a collection of data and functions # Object is an instance of a class # Class is a blueprint for an object class MyClass2: a = 10 def hello(self): print(’Hello World’) print(MyClass2.a) class Calculate: def add(self, num1, num2): return num1 num2 def multip ... #RaghavPal #How_to_create_Python_classes #How_to_define_attributes_in_Python_classes #How_to_define_methods_in_Python_classes #How_to_instantiate_Python_objects #How_to_access_attributes_in_Python_objects #How_to_call_methods_in_Python_objects #Python_classes_vs_functions 20230726 3rw_pkmtN24
Back to Top