- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Swap Two Variables using Python?
By using a temporary variable −
>>> x=10 >>> y=20 >>> z=x >>> x=y >>> y=z >>> x,y (20, 10)
Without using temporary variable
>>> a,b=5,7 >>> a,b (5, 7) >>> a,b=b,a >>> a,b (7, 5)
Advertisements