- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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)
- Swap two variables in one line in using Python?
- Swap two variables in one line using C#
- Swap two variables in one line in using Java
- How to swap two String variables without third variable.
- Swap two variables in one line in Java
- Swap two variables in one line in C/C+
- Swap two variables in one line in C/C++, Python, PHP and Java
- How to remove swap files using Python?
- How to compare two variables in an if statement using Python?
- Java program to swap two numbers using XOR operator
- How to swap two numbers without using a temp variable in C#
- How to swap two arrays without using temporary variable in C language?
- Java program to swap two integers