Home Whiteboard Practice Code Graphing Calculator Online Compilers Articles Tools

Explore Categories

Find the perfect tutorial for your learning journey

Python TechnologiesDatabasesComputer ProgrammingWeb DevelopmentJava TechnologiesComputer ScienceMobile DevelopmentBig Data & AnalyticsMicrosoft TechnologiesDevOpsLatest TechnologiesMachine LearningDigital MarketingSoftware QualityManagement Tutorials View All Categories
Tutorials Courses Jobs Login
Technical Questions and Answers

Article Categories

  • All Categories
  • Data Structure Data Structure
  • Networking Networking
  • RDBMS RDBMS
  • Operating System Operating System
  • Java Java
  • MS Excel MS Excel
  • iOS iOS
  • HTML HTML
  • CSS CSS
  • Android Android
  • Python Python
  • C Programming C Programming
  • C++ C++
  • C# C#
  • MongoDB MongoDB
  • MySQL MySQL
  • Javascript Javascript
  • PHP PHP
  • Economics & Finance Economics & Finance
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

How to Swap Two Variables using Python?

Python Server Side Programming Programming

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)
Jayashree
Jayashree

Updated on: 2020-03-02T07:40:44+05:30

529 Views

Learn More in Our Tutorials

  • Swapping Two Numbers Without Variable Learn C By Examples
  • Swapping Two Numbers Using Variable in C Learn C By Examples
Tutorix - AI Tutor
Previous Next
Advertisements
Tutorix AI Tutor for Cambridge — IGCSE and AS/A Level, live voice-led AI tutor
  • ABOUT US
  • OUR TEAM
  • CAREERS
  • JOBS
  • CONTACT US
  • TERMS OF USE
  • PRIVACY POLICY
  • REFUND POLICY
  • COOKIES POLICY
  • FAQ'S
tutorials point logo
Download Android App Download IOS App

Tutorials Point is a leading Ed Tech company striving to provide the best learning material on technical and non-technical subjects.

Copyright 2026. All Rights Reserved.