Thursday, January 23, 2020

how to write a basic class in python

class Student:
    def read(self):
        print("Reading student class")
     
s=Student()
s.read()

outputL
Reading student class


you can call multiple times
class Student:
    def read(self):
        print("Reading student class")
     
s=Student()
s.read()
s.read()
s.read()
s.read()

output:
Reading student class
Reading student class
Reading student class
Reading student class


example 2:
class Student:
    def __init__(self,x,y,z):
        self.name=x
        self.rollno=y
        self.marks=z
 
       
s=Student("anil",100,90)
print(s.name,s.rollno,s.marks)

output:
anil 100 90

No comments:

Post a Comment

python class topic video