Swapping Two Numbers Without Using Third Variable | Python Interview Questions for DevOps | 01

preview_player
Показать описание
Python Interview Questions for DevOps

Hey guys,

Welcome back to another video in the series. In today's video, we are going to talk about the prerequisites of this course. We will discuss these programs:

1) Swapping two numbers without using third variable
2) Calculating average

Like | Share | Subscribe | Follow
Рекомендации по теме
Комментарии
Автор

In one line only we can use know x, y=y, x without using third variable
x, y=5, 10
print("Before swapping x is {} and y is {}".format(x, y))
x, y=y, x
print("After swapping x is {} and y is {}".format(x, y))

sumacc
Автор

a=int(input("Enter the number A:"))#a=10
b=int(input("Enter the number B:"))#b=20
a=a+b #10+20=30
b=a-b #30-20=10
a=a-b
print("A:", a, "B:", b)

Ananth-
Автор

For number swap what is the logic behind using the if and else? As far as I can tell they are unnecessary and then you simplify the code significantly. Is there a hidden expectation I'm not aware of?

jerrycutshaw
Автор

bhai please sab hindi me banate rhna or any artificical intelligence technique hindi me bhi ban de

bvilnkt
welcome to shbcf.ru