Swap Two Strings in Python Perfect Way Using Function

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 


Most Popular

7 AWS Interview Questions asked in Infosys, TCS

How to Decode TLV Quickly

Hyperledger Fabric: 20 Real Interview Questions