{"id":20563,"date":"2021-09-15T19:49:08","date_gmt":"2021-09-15T14:19:08","guid":{"rendered":"https:\/\/python-programs.com\/?p=20563"},"modified":"2021-11-22T18:36:19","modified_gmt":"2021-11-22T13:06:19","slug":"python-program-for-swapping-three-variables-without-using-any-temporary-variable","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-swapping-three-variables-without-using-any-temporary-variable\/","title":{"rendered":"Python Program for Swapping Three Variables Without Using any Temporary Variable."},"content":{"rendered":"

In the previous article, we have discussed Python Program to Toggle the Last m Bits<\/a><\/p>\n

Given three numbers and the task is to swap the given three numbers without using any temporary variable in python<\/p>\n

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

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

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

Given first number= 30\r\nGiven second number= 45\r\nGiven third number= 21<\/pre>\n

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

The above given three numbers before swapping :\r\nfirst number =  30 second number =  45 third number =  21\r\nThe above given three numbers after swapping without using temporary variable:\r\nfirst number =  21 second number =  30 third number =  45<\/pre>\n

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

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

Given first number= 60\r\nGiven second number= 80\r\nGiven third number= 70<\/pre>\n

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

The above given three numbers before swapping :\r\nfirst number =  60 second number =  80 third number =  70\r\nThe above given three numbers after swapping without using temporary variable:\r\nfirst number =  70 second number =  60 third number =  80<\/pre>\n

Program for Swapping Three Variables Without Using any Temporary Variable in Python<\/h2>\n

Below are the ways to swap given three numbers without using any temporary variable in python:<\/p>\n