Swap Two Strings in Python Perfect Way Using Function

You can swap Two Strings in Python without the need to define the third variable. You can achieve this with function. Here's an example for your practice.

Python Swap Strings without Third Variable
Python ideas

How to Swap Two Strings

You can use multiple arguments in the function. Here, I've given 'a' and 'b' as arguments for the swap function. When you use the swap function, you will get swapped result.

def swap(a, b): 
return b,a 

Use the above function to swap Strings.

i = "Hello world"
j = "This is ApplyBigAnalytics" 

(i, j) = swap(i, j) 


Example to Swap Two Numbers.

i = 1 
j = 2 

(i, j) = swap(i,j) 


The Result is:

This is ApplyBigAnalytics 
Hello world 


Popular posts from this blog

How to Fix Python Syntax Errors Quickly

7 AWS Interview Questions asked in Infosys, TCS

Hyperledger Fabric: 20 Real Interview Questions