0
How do I replace characters in a function instead of a string?
5 ответов
+ 6
Alba Robledo ,
the best thing is when mistakes don't occur at all.
anyway, using a regular ide has mostly a search / replace function that you can use. unfortunately sololearn does not have such a possibillity in playground.
i would not recommend you to do a program by yourself that can do search and replace because you will also need to have undo / redo functionality. do not use "replace all", the most replace functions can step to all *hits* and you can decide if it should perform this item or skip it.
use a text editor, copy your code and paste it to the editor. do your search / replacements.
finally copy the result and past it back to your editor.
btw: your sample of *correcting* "helo" to "hello" will allso *correct* any other "l" and duplicate it...
+ 3
# how about passing an argument to the function?
def sayhello(sth):
print(sth)
+ 2
It is unclear to me what you want to do. Please give an example before and after replacement.
+ 1
yeah that was only an example, I need to replace a lot of things at once cause I made the same mistake over an over in a lot of long code. looking something similar to replace but for entire code/funtions instead of strings
0
Inside a def funtion, replace the characters (to fix a mistake all at once)
Example:
def sayhello:
print("helo")
Replace with
def sayhello:
print("hello")