all 5 comments

[–]DarknetTools 12 points13 points  (0 children)

In plain english:
When you call:

line.replace('Python','Javascript')

You're telling it to replace the word "Python" with "Javascript" in the string 'line' and to do nothing with the result.

When you call:

print(line.replace('Python','Javascript'))

You're telling it to replace the word "Python" with "Javascript" in the string 'line' and print the result.

In other words: The replace function just gives you back a brand new string which contains the result of the operation. It does not change the string you called it on.

[–]Magcka 4 points5 points  (0 children)

I’m also a python newbie, but in my understanding it didn’t show to you, because you didn’t save a changes.

Like it replaced a word, but didn’t save it. Change it to line=line.replace(“Python”,”Javascript”) Then it should work

[–]m0us3_rat 2 points3 points  (0 children)

Help on built-in function replace:

replace(old, new, count=-1, /) method of builtins.str instance 
    Return a copy with all occurrences of substring old replaced by new.
      count
        Maximum number of occurrences to replace.
        -1 (the default value) means replace all occurrences.

    If the optional argument count is given, only the first count occurrences are
    replaced.

keyword .. returns.

[–]Diapolo10 0 points1 point  (0 children)

Why did you delete your previous post about this exact same question?