Skip to content

Instantly share code, notes, and snippets.

@charanhu
Created October 11, 2022 13:29
Show Gist options
  • Save charanhu/7efc7c151a8ba57da9473923f86f153c to your computer and use it in GitHub Desktop.
Save charanhu/7efc7c151a8ba57da9473923f86f153c to your computer and use it in GitHub Desktop.
# Example 1: getattr() function
class Person:
def __init__(self, age):
self.age = age
# create a Person object with age 36
person = Person(36)
# get the value of the attribute 'age'
print('The age of Person ',getattr(person, 'age', 40))
# get the value of the attribute 'salary'
print('The salary of Person ',getattr(person, 'salary', 10000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment