class method

class myclass:
class_teacher = "niraj sir"

def __init__(self, name1, roleno1, aim1):
self.name = name1
self.role_no = roleno1
self.aim = aim1

# u have to use decorator for using classmethod
@classmethod # it works on class variables
def setstream(cls, stream):
myclass.stream1 = stream


myclass.setstream("science")

student1 = myclass("harish", 1, "software engineer")
student2 = myclass("shiva", 2, "hacker")

print(student2.stream1)

Comments

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C