satya

Sunday, January 3, 2021

Program 31

                                                                            Program 31

Write a Python class to reverse a string word by word.

class Sa:

    def display(self,s):

        words = s.split(' ')  

        reverse_sentence = ' '.join(reversed(words))  

        print("The reverse words of string:",reverse_sentence) 

  

k=Sa()

s = input("enter the string:")

k.display(s)



OUTPUT:

=== RESTART: C:/Users/crrcse/Desktop/30.py =======

enter the string:welcome to python 

The reverse words of string:  python to welcome

>>> 


No comments:

Post a Comment

Program 30

                                                                         Program 30 Write a Python class to implement pow(x, n). class Pow1:...