Hello friends!!!!!

Pgr to change the default name in the parent class

PYTHON

11/10/20241 min read

'''

"@classmethod" is a decorator useful in helping the function in changing the class attribute

'''

#changing the default name

class person:

name = "Rishi"

@classmethod

def change_name(cls,name):

cls.name = name

s1 = person()

s1.change_name("Rishendra")

print(s1.name)

print(person.name)

Output:

Rishendra

Rishendra

=== Code Execution Successful ===