Reverse by Python string word

Asked 1 years ago, Updated 1 years ago, 106 views

Hello, it's nothing but

a = input("")
print (a[::-1])

For example, "how are you" is "uoyera woh". I'd like to make each spelling upside down, not backwards, but backwards based on spacing. If it's "how are you", I want to change it to "you are how" I'm asking you this question because I can't do it I beg you. And I really want to use the input function.

input indexing split python

2022-09-21 11:47

3 Answers

Please note that there is also a method as below.

s = 'how are you'
' ' '.join(reversed(s.split()))
'you are how'


2022-09-21 11:47

 a = 'how are you'
b = a.split(" ")
ab = ''
b
#['how', 'are', 'you']

for i in range(len(b), 0, -1):
    ab += b[i-1] + " 
print(ab)
#you are how 

If you can't do it after trying it, please refer to it.


2022-09-21 11:47

a = input().split(' ')

print(a[::-1])

All you have to do is attach the .split('')


2022-09-21 11:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.