The Perfect Way to Swap two Strings in Python

Without a third variable, you can swap strings in Python. With the swap function, you can achieve this. Here's the sample logic. 

Python Swap Strings without Third Variable
Python ideas

Swap two strings

Multiple arguments you can use in the same function. Here, a and b are arguments for the swap function. You'll get output as swapped when you use the swap function.

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

Logic to swap strings.

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

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


Logic to Swap two numbers.

i = 1 
j = 2 

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


Here is output

This is ApplyBigAnalytics 
Hello world 

Post a Comment

Thanks for your message. We will get back you.

Previous Post Next Post