Created
October 11, 2022 13:29
-
-
Save charanhu/7efc7c151a8ba57da9473923f86f153c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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