
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
What does delattr() function do in Python?
Python delattr()
The delattr() deletes an attribute from the object if the object allows it.
Syntax
The syntax of delattr() is −
delattr(object, name)
The delattr() method takes two parameters −
The delattr() doesn't return any value (returns None). It only removes an attribute (if object allows it).
Example
class Coordinate: x = 12 y = -7 z = 0 point1 = Coordinate() print('x = ',point1.x) print('y = ',point1.y) print('z = ',point1.z) delattr(Coordinate, 'z') print('--After deleting z attribute--') print('x = ',point1.x) print('y = ',point1.y) # Raises Error print('z = ',point1.z)
Output
This gives the output
Traceback (most recent call last): ('x = ', 12) ('y = ', -7) File "C:/Users/~.py", line 28, in <module> ('z = ', 0) print('z = ',point1.z) --After deleting z attribute-- ('x = ', 12) AttributeError: Coordinate instance has no attribute 'z' ('y = ', -7)
- Related Articles
- What does setattr() function do in Python?\n\n
- What does built-in class attribute __name__ do in Python?\\\\n\\\\n
- What does reload() function do in Python?
- 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 os.pipe() function do in Python?
- What does getattr() function do in Python?
- What does hasattr() function do in Python?
- What does the method listIterator(n) do in java?
- delattr() and del() in Python
- What does the repr() function do in Python Object Oriented Programming?
- What does the str() function do in Python Object Oriented Programming?

Advertisements