Write a Python Class to Reverse a String Word by Word

 In this article, we will write a python class to reverse a string word by word.

Write a Python Class to Reverse a String Word by Word

class py_solution: def reverse_words(self, s): return ' '.join(reversed(s.split())) print(py_solution().reverse_words('hello python')) print(py_solution().reverse_words('python source code examples')) 

Output:

python hello examples code source python

Comments