

- 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 does setattr() function do in Python?
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.
Example
class Male: name = 'Abel' x = Male() print('Before modification:', x.name) # setting name to 'Jason' setattr(x, 'name', 'Jason') print('After modification:', x.name)
Output
This gives the output
('Before modification:', 'Abel') ('After modification:', 'Jason')
- Related Questions & Answers
- What does raw_input() function do in python?
- What does input() function do in python?
- What does print() function do in Python?
- What does open() function do in Python?
- What does close() function do in Python?
- What does reload() function do in Python?
- What does os.pipe() function do in Python?
- What does getattr() function do in Python?
- What does hasattr() function do in Python?
- What does delattr() function do in Python?
- What does the repr() function do in Python Object Oriented Programming?
- What does the str() function do in Python Object Oriented Programming?
- What does the cmp() function do in Python Object Oriented Programming?
- What does the .end() function do in jQuery?
- What does a +function() { } notation do in JavaScript?
Advertisements