0

About this lesson"list operations"May I know how can we replace one letter of a string by another?

29th May 2019, 10:21 AM
Orneil
Orneil - avatar
4 Answers
+ 3
Are you talking about python? To get it clear please give a sample of list, and what you are going to replace. But anyway it is recommended to continue the lesson.
29th May 2019, 11:17 AM
Lothar
Lothar - avatar
+ 3
OK so thats very simple. if you will keep the original list as it is, use a new list for result. newlst = Name.replace(‘w’, ‘y’) (generally it is recommended to use lowercase naming for variables) In this case all ‘w’ in the string will be replaced. If you only want to replace one ‘w’ there is a third argument: x=input("Enter a number you want to add in the list") newlst = Name.replace(‘w’, ‘y’, 1) this will replace the first ‘w’ only.
29th May 2019, 11:46 AM
Lothar
Lothar - avatar
+ 1
Thanks a lot
11th Jun 2019, 11:01 PM
Orneil
Orneil - avatar
0
A simple example Name=["hello world"] And I just want to replace "w" by "y" even if that doesn't have a sense
29th May 2019, 11:25 AM
Orneil
Orneil - avatar