Posts

Showing posts with the label Swap

Swap Two Strings in Python Perfect Way Using Function

Image
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 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)  print(i)  print(j)  Example to Swap Two Numbers. i = 1  j = 2  (i, j) = swap(i,j)  print(i)   print(j) The Result is: This is ApplyBigAnalytics  Hello world  2  1 Keep Reading The Real Purpose of Underscore in Python