Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Example functions:
- print (hasattr(emp1, 'location')) # Returns true if 'location' attribute exists
- print (getattr(emp1, 'name’)) # Returns value of 'name' attribute
- print (setattr(emp2, 'location', ‘Delhi’)) # Set attribute 'location' to Delhi (note single
- quotes are used when specifying the value)
- print (delattr(emp1, 'empid')) # Delete attribute 'empid’
- Respective outputs
- False - for hasattr(emp1, 'location')
- 1104 - for getattr(emp1, 'name’)
- None - for setattr(emp2, 'location', ‘Delhi’)
- None - for delattr(emp1, 'empid')
Add Comment
Please, Sign In to add comment