self.stock: print("Enter the value less then stock") else: print("Total Prices", q * 100) self.stock = self.stock - q print("Total Bikes", self.stock) while True: obj = BikeShop(100) uc = int(input(''' 1. Display Stocks 2. Rent a Bike 3. Exit ''')) if uc == 1: obj.displayBike() elif uc == 2: n = int(input("Enter the Qty:---")) obj.rentForBIke(n) else: break "> self.stock: print("Enter the value less then stock") else: print("Total Prices", q * 100) self.stock = self.stock - q print("Total Bikes", self.stock) while True: obj = BikeShop(100) uc = int(input(''' 1. Display Stocks 2. Rent a Bike 3. Exit ''')) if uc == 1: obj.displayBike() elif uc == 2: n = int(input("Enter the Qty:---")) obj.rentForBIke(n) else: break "> self.stock: print("Enter the value less then stock") else: print("Total Prices", q * 100) self.stock = self.stock - q print("Total Bikes", self.stock) while True: obj = BikeShop(100) uc = int(input(''' 1. Display Stocks 2. Rent a Bike 3. Exit ''')) if uc == 1: obj.displayBike() elif uc == 2: n = int(input("Enter the Qty:---")) obj.rentForBIke(n) else: break ">
class BikeShop:
def __init__(self, stock):
    self.stock = stock

def displayBike(self):
    print("Total Bikes", self.stock)

def rentForBIke(self, q):

    if q <= 0:
        print("Enter the greater value")
    elif q > self.stock:
        print("Enter the value less then stock")
    else:
        print("Total Prices", q * 100)
        self.stock = self.stock - q
        print("Total Bikes", self.stock)
while True:
obj = BikeShop(100)
uc = int(input('''
1. Display Stocks
2. Rent a Bike
3. Exit
'''))
if uc == 1:
obj.displayBike()
elif uc == 2:
n = int(input("Enter the Qty:---"))
obj.rentForBIke(n)
else:
break

Class and Objects :

Class is the blueprint of obj , function inside the class and call through obj.

class DemoClass:  # Camel case
a = 10
def __init__(self): # it is constructor it is called automatically through object. 
#No need to call the function
    print("Example of  constructor")

def sum1(self):  # one argument is necessary in the method, it is called method , 
# function and method are similar but function can be defined outside the class
    print(20 + 30)
    print(self.a)  # while calling this function through obj and if we wont use self then 
# it shows var is not defined
    c = 10
    b = 10
    d = c + b
    print(d)

def showvalue(self, a, b):
    print("Welcome to Python")
    print(a + b)
demoobject = DemoClass()  # created an object, and can create many object from one class, 
# constructor will call by it
sumobj = DemoClass() # constructor will be call by it.
print(demoobject.a)  # will print value var
sumobj.sum1();  # it will call the method sum1

Methods(need to call it) and Constructor (it not need to call, it will be called itself)

Inheritance: Single, Multilevel and Multiple

class A:

def displayA(self):
	print("This is Class A")
class B(A):  # Single Inheritance, the method of class A will be inherited in class B

def displayB(self):
	print("This is Class B")
class C(B):  # Multilevel Inheritance,

def displayC(self):
	print("This is Class C")
obj = C()  # created object of C in which the method Class B has inherited in class B, 
# A is inherited
obj.displayA()  # calling class A method with obj of B
obj.displayB()
obj.displayC()

Multiple Class

class A1:
def displayA(self):
	print("This is Class A1")
class B1:  # Single Inheritance, the method of class A will be inherited in class B

def displayB(self):
	print("This is Class B1")
class C1(B1,A1):  # Multiple Inheritance,Java,PHP doesnt support Multiple inheritance

def displayC(self):
	print("This is Class C1")
obj = C1()  # created object of C in which the Class A & B  is together inherited
obj.displayA()  # calling class A method with obj of B
obj.displayB()
obj.displayC()

Encapsulation :

Getter and Setter Method(user created method) , not directly accessible , kind of private, e.g. Mouse(don't no what is going inside the mouse but just working of it) , can set value in private and get it.

class Student:
__name1 = "Nihal"  # __ defines as it is private and can be accessible to ues it we have to use constructor

def **init**(self):
	print(self.__name1)
	self.__name = ""  # it is private var
	self.__function1() # private function can be called by only constructor ,

def __function1(self):
	print("This is Private Function")

def getname(self):
	return self.__name # now the value of the __name is here after the execution of setname function

def setname(self, name): # 1st function called by obj is setname where Testing is passed and being stored
    # in private var __name
    self.__name = name

obj = Student() # constructor will be called by it automatically
obj.setname("Testing") # Calling function set and passing = Testing
nam = obj.getname() # after stored in __name var we will get it  from getname function and storing in new var nam
print(nam)

Polymorphism :

Used for overloading and overriding ,same function name being uses for different types.