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) Kartik print(p1.age) 36 p1.myfunc() Hello my name is Kartik p1.age = 35 print(p1.age) 35 print(type(p1)) <class '__main__.Person'> print(type(p1.age)) <class 'int'> print(type(type(Person))) <class 'type'> del 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() Nagar Kartik class Person: def __init__(self, fname, lname)
FOR BEGINNER PROGRAMMER & COMPUTER SCIENCE STUDENTS