How to invert a string in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to invert a string in python

Ex: Air Ria

17th Dec 2019, 10:10 AM
Arydev
Arydev - avatar
7 Answers
+ 1
To replace a string, use the following code: 1) string="hi world" 2) new_string=string.replace ("hi","hello") 3) print (new_string) ***output***: hello world
18th Dec 2019, 3:00 PM
🇲​🇴​🇭​🇦​🇲​🇲​🇦​🇩​ 🇯​🇮​🇱​🇦​🇳​
🇲​🇴​🇭​🇦​🇲​🇲​🇦​🇩​ 🇯​🇮​🇱​🇦​🇳​ - avatar
+ 6
Arydev , if your string is for example s = "Air", you can use s[:: - 1] to slice it backwards 🐱
17th Dec 2019, 10:33 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
Arydev , please look at the code. Hope now everything is clear 🐱 https://code.sololearn.com/c7aoNwSsP98C/?ref=app
17th Dec 2019, 10:42 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
How to replace a string
17th Dec 2019, 10:33 AM
Arydev
Arydev - avatar
0
Is clear i understand it
17th Dec 2019, 11:28 AM
Arydev
Arydev - avatar
18th Dec 2019, 9:30 PM
Ipang
0
name = 'Air' # Change Air to Ria name_change = name[::-1].lower() #Change the str to lower user_output = name_change.capitalize() #Capitalize print(user_output)
20th Dec 2019, 10:25 AM
Dilji
Dilji - avatar