

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is difference in getattr() and setattr() functions in Python?
The getattr() method
The getattr() method returns the value of the named attribute of an object. If not found, it returns the default value provided to the function.
Syntax
The syntax of getattr() method is −
getattr(object, name[, default])
The getattr() method can take multiple parameters −
The getattr() method returns −
value of the named attribute of the given object
default, if no named attribute is found
AttributeError exception, if named attribute is not found and default is not defined
The setattr() method
The setattr() method sets the value of given attribute of an object.
Syntax
The syntax of setattr() method is −
setattr(object, name, value)
The setattr() method takes three parameters −
The setattr() method returns None.
- Related Questions & Answers
- What is difference between raw_input() and input() functions in Python?
- What does setattr() function do in Python?
- What does getattr() function do in Python?
- What is the difference between Python functions datetime.now() and datetime.today()?
- Python - getattr() method
- What is the difference between dir(), globals() and locals() functions in Python?
- What is the difference between functions and methods in JavaScript?
- What is the difference between CONCAT() and CONCAT_WS() functions?
- What is the difference between virtual and abstract functions in C#?
- What is the difference between anonymous and inline functions in JavaScript?
- What is the difference between jQuery.map() and jQuery.grep() Functions in jQuery?
- What is the difference between jQuery.map() and jQuery.each() Functions in jQuery?
- What is the difference between ajaxSend() and ajaxStart() functions in jQuery?
- What is the difference between ajaxStop() and ajaxComplete() functions in jQuery?
- What is the difference between ajaxSuccess() and ajaxComplete() functions in jQuery?
Advertisements