12-21-2020 Python

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

class student:

#sample class Attribute


attr1="cuca"
attr2="cybersecurity"
#samle method
def fun(self):
print("I'm a",self.attr1)
print("I'm a",self.attr2)

#call my class usimg an object


obj=student()
#invoking attribute inside the class
print(obj.attr1)
#invoke method through objects
obj.fun()
class csstudent:
#class variable
stream='cse'
#init method
def __init__(self,name,roll):
self.name=name
self.roll=roll
#instance variable

#objects for the class


a=csstudent("student",101)
b=csstudent("cuca",102)
#invoking my class variable using the object
print(a.stream)
print(b.stream)
print(a.name)
print(b.name)
print(a.roll)
print(b.roll)
#invoking my class variable using the class Name
print(csstudent.stream)

You might also like