
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Assign Multiple Values to a Variable in Python
In Python, if you try to do something like
a = b = c = [0,3,5] a[0] = 10
You'll end up with the same values in
a, b, and c: [10, 3, 5]
This is because all three variables here point to the same value. If you modify this value, you'll get the change reflected in all names, ie, a,b and c. To create a new object and assign it, you can use the copy module.
example
a = [0,3,5] import copy b = copy.deepcopy(a) a[0] = 5 print(a) print(b)
Output
This will give the output −
[5,3,5] [0,3,5]
Advertisements