Posts

Showing posts from February, 2024

Python inheritance

Image
Inheritance is one of the OOP(Object Oriented Programming) Concept. It involves a parent and child class. A class is created and its member functions are defined. This class is called base class or parent class. When you want a copy of base class, you can inherit it   and create a child class. A child class is simply a replica of base class. 1)Here, a base class is created with name " customer" class customer:   def __init__(cust, fname, lname):     cust.firstname = fname     cust.lastname = lname      def printfullname(cust):     print(cust.firstname, cust.lastname) #Use the customer class to create an object, and then execute the printfullname method: x = customer("jeev", "anand") x.printfullname()   2) A child class “Regularcustomer” is created. #Creating a child class Regularcustomer class Regularcustomer(customer):   pass # pass denotes this class doesnot have any d...

Object oriented concepts -Classes and objects

Image
 Everything is an object in real world. In object-oriented programming, basic term is classes and objects. Class is a collection of objects and methods. Each class has some properties and functionalities. For eg, A car is a class. Name of the car is like the classname. Brand of the car, color and size are the properties of the class. Running is the functionality of a car. It is the method. Let us create a class in python. Here, the code begins… Syntax:   class classname:                    Variablename Eg: class SampleClass:                S = 10 Next, an object is created. The object accesses the Sum variable and it gets printed.         Ob = SampleClass()         Print(Ob.sum) Add this code in a file “SampleClass.py”. While execu...