
- 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 immutable mean? Which Python types are mutable and which are not?
In Python, there are two types of Objects.
- Mutable Object
- Immutable Object
Mutable: Mutable objects are modified, (i.e) objects are a changeable list, set, dict, etc are mutable.
mutable objects are easy to change.
Example 1
list =["Tutorials ","Point", "Pvt","Ltd"] list[2]= 'Tutorix' list
Output
['Tutorials ', 'Point', 'Tutorix', 'Ltd']
Example 2
list=['Car','Bike','Scooty','Bus','Metro'] list[4]= 'Bicycle' list
Output
['Car', 'Bike', 'Scooty', 'Bus', 'Bicycle']
Immutable: immutable objects are not modified (i.e) not changeable int, float, bool, str, tuple, Unicode, etc ... are immutable. immutable objects are expensive and difficult to change. a tuple is enclosed within the parenthesis tuples are immutable and can't be changed.
Example 1
tuple=('1','2','Python','Perl') tuple
Output
('1', '2', 'Python', 'Perl')
Example 2
tuple=('1','2','Python','Perl') tuple[4]='2019' tuple
Output
TypeError Traceback (most recent call last) in 1 tuple=('1','2','Python','Perl') ----> 2 tuple[4]='2019' 3 tuple TypeError: 'tuple' object does not support item assignment
tuple object cant be changed by seeing above output you get a clear understanding
- Related Questions & Answers
- Which data types are immutable in Python?
- Difference between mutable and immutable in python?
- Difference between mutable and immutable object
- What are the different types of stylish bottoms for women which I may not know of?
- What are the types of process scheduling algorithms and which algorithms lead to starvation?
- Python - Show which entries in a Pandas Index are not NA
- Which characters are NOT allowed in MongoDB field names?
- What are the symptoms of bird flu which should not be ignored?
- Which grapes are the tastiest?
- What are plagiarism tools and which is best to use?
- Find the element before which all the elements are smaller than it, and after which all are greater in Python
- How can you avoid getting an error if you are deleting a table which does not exist using Python?
- What is the difference between a mutable and immutable string in C#?
- What are the different wildcard characters which can be used with NOT LIKE operator?
- Program to remove all nodes from BST which are not in range in Python
Advertisements