Posts

Showing posts from March, 2021

Python Class and Objects

Image
Python Class and Objects What is class and object ? class :- it is a structure which is used to where you put your data and any function that you want  for example : if you buy any house it is full empty in that room you see a kitchen, bedroom, hall this we example of class and when you put something in the house like T.V, A.C, Sofa more.. it means you put some value on the class . in above left image is a class with no value and in right their is a class with value  for understanding replace class with hall and value with (TV, Sofa etc..) How we can implement class and object in python ? To create a class, use the keyword  class : Example : class   Room :         total_sofa =  5 this way we create class in python. How we can access class variable (ex: total_sofa ) value ? Answer: by using "object" let me explain don't get confuse  To create a object, we use : syntax : object = class_name() Create an object named p1, and print the value of total_sofa: Example : p1 = Room