SWAPPING

SWAPPING

 Swapping, in the context of programming, refers to the process of interchanging the values of two variables. It involves taking the value of one variable and assigning it to the other variable, while simultaneously taking the value of the second variable and assigning it to the first variable. As a result, the original values of the variables are exchanged.

Swapping is commonly used in programming when there is a need to rearrange or manipulate data between two variables. It can be done using a temporary variable to hold one of the values temporarily, or by utilizing language-specific techniques that allow direct swapping without the need for an intermediary variable.

Swapping variables is useful in various scenarios, such as sorting algorithms, data transformations, or when you need to update variable assignments based on changing conditions.

In Python, swapping refers to exchanging the values of two variables. Swapping allows you to interchange the values stored in two variables, effectively switching their contents.

CODE:

# Initial values a = 10 b = 20 # Swap the values a, b = b, a # Print the swapped values print("a =", a) print("b =", b)

OUTPUT:

a = 20

b = 10



Comments

Popular posts from this blog

ILLUSTRATIVE PROGRAMS IN PYTHON

Fibonacci Series

The Fibonacci series