How to swap the first and last character from a string in Python

1 Answer

0 votes
def change_first_and_last_character(str):
      return str[-1:] + str[1:-1] + str[:1]
	  
print(change_first_and_last_character('python'))

 
 
 
 
'''
run:
 
nythop
 
'''

 



answered Aug 31, 2021 by avibootz

Related questions

...