You can easily swap values without temp (temporary variable) in Python.  It is possible to swap values of variables and to swap values (elements) in a list.

So, how to swap letters in Python assignment!

# Initializing list  list1 = ['SA']     # print lists  print("The list is : " + str(list1))     # Swap elements  res = [sub.replace('S', '-').replace('-', 'A') for sub in list1]     # print result   print ("List after swaps : " + str(res))

If you run the program to swap the letters in the Python compiler, then the following output will be shown on your display screen.

The list is : ['SA'] List after swaps : ['AA']

Do you find this useful? If yes, then you must try this program and keep on practicing. If you have any doubt, then take experts' help.

Consider us to take solutions to swap letters in python assignment expert. Hit the button to reach them today!