{"id":7305,"date":"2023-11-01T10:19:16","date_gmt":"2023-11-01T04:49:16","guid":{"rendered":"https:\/\/python-programs.com\/?p=7305"},"modified":"2023-11-10T12:11:04","modified_gmt":"2023-11-10T06:41:04","slug":"python-program-to-swap-two-variables","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-swap-two-variables\/","title":{"rendered":"Python Program to Swap Two Variables"},"content":{"rendered":"

Swapping:<\/strong><\/p>\n

Swapping two variables in computer programming means that the variables values are swapped.<\/p>\n

Given two variables x , y the task is to swap the variable values.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:(Integer Values Swapping)<\/strong><\/p>\n

Input:<\/strong><\/p>\n

p=1372 q=4129<\/pre>\n

Output:<\/strong><\/p>\n

printing the values of integer variables p and q before swapping\r\np = 1372\r\nq = 4129\r\nprinting the values of integer variables p and q after swapping\r\np = 4129\r\nq = 1372<\/pre>\n

Example2:(Boolean Values Swapping)<\/strong><\/p>\n

Input:<\/strong><\/p>\n

p=True q=False<\/pre>\n

Output:<\/strong><\/p>\n

printing the values of boolean variables p and q before swapping\r\np = True\r\nq = False\r\nprinting the values of boolean variables p and q after swapping\r\np = False\r\nq = True<\/pre>\n

Example3:(Decimal Values Swapping)<\/strong><\/p>\n

Input:<\/strong><\/p>\n

p = 2738.321  q = 83472.421<\/pre>\n

Output:<\/strong><\/p>\n

printing the values of decimal variables p and q before swapping\r\np = 2738.321\r\nq = 83472.421\r\nprinting the values of decimal variables p and q after swapping\r\np = 83472.421\r\nq = 2738.321<\/pre>\n

Example4:(String Values Swapping)<\/strong><\/p>\n

Input:<\/strong><\/p>\n

p=\"Vicky\" q=\"Tara\"<\/pre>\n

Output:<\/strong><\/p>\n

printing the values of string variables p and q before swapping\r\np = vicky\r\nq = Tara\r\nprinting the values of string variables p and q after swapping\r\np = Tara\r\nq = vicky<\/pre>\n

Swapping two Variables in Python<\/h2>\n

There are several ways to swap two variables in Python some of them are:<\/p>\n