0
About this lesson"list operations"May I know how can we replace one letter of a string by another?
4 Respuestas
+ 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.
+ 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.
+ 1
Thanks a lot
0
A simple example
Name=["hello world"]
And I just want to replace "w" by "y" even if that doesn't have a sense