How to reverse the order of the words in a string with Python

1 Answer

0 votes
string = 'python java c c++'

lst = string.split(' ')
lst.reverse()

string = ' '.join(lst)

print(string)  
 


'''
run:

c++ c java python

'''
 
 

 



answered Aug 6, 2022 by avibootz
...