🐍Python Program #8: Swap Two Numbers Without Using a Third Variable | Python Programming
#python #pythonprogramming #pythonforbeginners #swap #swapping #pythontutorial #python3
This Python trick shows how to swap two variables without using a third one! Great for interviews and logical thinking.
1. You have two numbers: a = 5, b = 10.
2. Normally, to swap, we need a temporary variable.
But here, we’ll do it using math (no third variable!).
3. Step-by-step:
a = a + b → Now a = 15
b = a - b → Now b = 5 (original value of a)
a = a - b → Now a = 10 (original value of b)
4. This way, the values are swapped without any extra variable.
5. Print new values of a and b.
Try it yourself with any number!
Subscribe for more bite-sized Python codes 🐍
code:
a = 5
b = 10
a = a + b
b = a - b
a = a - b
print("After swapping:")
print("a =", a)
print("b =", b)
💬 Got questions? Drop them below!
❤️ Like + Subscribe for more 1-min Python gems!
🔔 Don’t forget to Like, Subscribe, and hit the bell icon for more short & powerful Python tutorials every week!
python,python for beginners,asmr programming,python programming,python program to swap two numbers using third variable, program to swap two numbers without using third variable, how to swap two numbers without using a third variable, python program to swap two variables without using third, python program is to swap two numbers using third variable, write a program to swap two numbers in python, program to swap two numbers without using the third variable, write a python program to swap two numbers, swap two numbers without using third variable in python 3 Python in 5 Minutes: Super Fast Beginner Guide
• Python in 5 Minutes: Super Fast Beginner G...
Python Variables and Data Types | Explained in 3 minutes with Examples | Python for Beginners
• Python Variables and Data Types | Explaine...
Master Python Loops (For loop & While loop) in Just 5 Minutes | Python For Beginners
• Master Python Loops (For loop & While loop...
💻Coding Python Calculator Program 🧮🐍
• 💻Coding Python Calculator Program 🧮🐍
How to Check If List is Empty in Python 🐍💻
• How to Check If List is Empty in Python 🐍💻
How to Reverse a String in Python Like a Pro!
• How to Reverse a String in Python Like a Pro!
Python Lists | 5 Cool Tricks of Lists in Python - You must know!
• 5 Cool Tricks To Use Lists in Python - You...
Python Programs | Python Programming - Playlist for logic building and practice
• Python Programs | Python Programming - Pla...
Nesta página do site você pode assistir ao vídeo on-line 🐍Python Program #8: Swap Two Numbers Without Using a Third Variable | Python Programming duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário All In Graphics 01 Julho 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 40 vezes e gostou 4 espectadores. Boa visualização!