Answers for "set object attribute python"

0

set object attribute python

class Student:
  marks = 88
  name = 'Sheeran'

person = Student()

# set value of name to Adam
setattr(person, 'name', 'Adam')
print(person.name)

# set value of marks to 78
setattr(person, 'marks', 78)
print(person.marks)

# Output: Adam
#         78
Posted by: Guest on September-24-2021

Code answers related to "set object attribute python"

Python Answers by Framework

Browse Popular Code Answers by Language