C
LASS/OBJECT & INHERITANCE
class Person:
def __init__(self1, name, age):
self1.name = name
self1.age = age
def myfunc(self2):
print("Hello my name is " + self2.name)
p1 = Person("Kartik", 36)
print(p1.name)
print(p1.age)
del p1
class Person:
pass
Python Inheritance
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
class Student(Person):
pass
x = Student("Nagar", "Kartik")
x.printname()
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def full(self):
print(self.firstname,self.lastname)
class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.graduationyear = year
def welcome(self):
print("Welcome" ,self.graduationyear, " Studens.")
x = Student("Kartik", "Nagar", 2019)
x.welcome()
LASS/OBJECT & INHERITANCE
class Person:
def __init__(self1, name, age):
self1.name = name
self1.age = age
def myfunc(self2):
print("Hello my name is " + self2.name)
p1 = Person("Kartik", 36)
print(p1.name)
Kartik
print(p1.age)
36
p1.myfunc()
Hello my name is Kartik
p1.age = 35print(p1.age)
35
print(type(p1))
<class '__main__.Person'>
print(type(p1.age))
<class 'int'>
print(type(type(Person)))
<class 'type'>
del p1.agedel p1
class Person:
pass
Python Inheritance
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
class Student(Person):
pass
x = Student("Nagar", "Kartik")
x.printname()
Nagar Kartik
class Person:def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def full(self):
print(self.firstname,self.lastname)
class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.graduationyear = year
def welcome(self):
print("Welcome" ,self.graduationyear, " Studens.")
x = Student("Kartik", "Nagar", 2019)
x.welcome()
Welcome 2019 Studens.
x.full()
Kartik Nagar
Comments
Post a Comment