Answers for "python getattr function"

2

getattr(A, command)(newSet)

class Person:
    age = 23
    name = "Adam"

person = Person()
print('The age is:', getattr(person, "age"))
print('The age is:', person.age)
Posted by: Guest on June-17-2020
0

python getattr function

class Student:
    name = 'John'
    age  = 24
  
student = Student()
  
print('Student name: ', getattr(student, 'name'))
print('Student age: ', getattr(student, 'age'))
  
# Output
# Student name:  John
# Student age:  24
Posted by: Guest on October-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language