Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

setattr python

# Per https://www.w3schools.com/python/ref_func_setattr.asp, 
# the setattr() function sets the value of the specified attribute of the specified object.

# Here is a sample code from https://www.w3schools.com/python/trypython.asp?filename=demo_ref_setattr
class Person:
  name = "John"
  age = 36
  country = "Norway"

setattr(Person, 'age', 40)

# The age property will now have the value: 40

x = getattr(Person, 'age')

print(x)
 
PREVIOUS NEXT
Tagged: #setattr #python
ADD COMMENT
Topic
Name
1+7 =