🌐
W3Schools
w3schools.com › python › ref_string_replace.asp
Python String replace() Method
Python Examples Python Compiler ... Q&A Python Bootcamp Python Training ... The replace() method replaces a specified phrase with another specified phrase....
🌐
Reddit
reddit.com › r/learnpython › using replace() method
r/learnpython on Reddit: Using replace() method
February 27, 2024 -

Hi guys, I had a quick question about the exercise I was working on.

For using the replace() method and printing the result, we have to assign it to another variable and print that new variable.

sentence = sentence.replace(‘hey’, ‘hi’) print(sentence)

But for something such as the sort method we don’t need to assign it to a new variable and just use it straight up.

list = […] list.sort() print(list)

Why is it that some methods you need to assign it to a new variable, while others work while not assigning it to a new variable and the original is changed. Thank you.

Sorry about format, I’m on mobile.

🌐
Mimo
mimo.org › glossary › python › string-replace-method
Master Python's String Replace Method for Text Manipulation
Start your coding journey with Python. Learn basics, data types, control flow, and more ... The replace() method returns a copy of the string after replacing the substrings without changing the original string.
🌐
AskPython
askpython.com › python › string › python-replace-function
Python replace() function - AskPython
May 21, 2026 - This behavior mirrors how Python handles other string operations documented in the Python string find() method. ... Parameters: old - substring to find and replace new - replacement substring count - max replacements (default: -1 = all) Returns: new string with substitutions applied
🌐
Programiz
programiz.com › python-programming › methods › string › replace
Python String replace()
The replace() method returns a copy of the string where the old substring is replaced with the new string.
🌐
Server Academy
serveracademy.com › blog › python-replace-function
Python Replace() Function Blog | Server Academy
2 days ago - The method in Python is a powerful tool for working with strings, allowing you to replace parts of a string with new values. Whether you’re changing characters…
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-replace
Python String replace() Method - GeeksforGeeks
3 weeks ago - It returns a new string with the replacements applied, while the original string remains unchanged.
🌐
Hyperskill
hyperskill.org › university › python › replace-method-in-python
Python replace() Method
July 17, 2024 - The Python replace method is a built-in string method used to replace occurrences of a given substring within a string with a new substring.
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.6 documentation
An f-string (formally a formatted string literal) is a string literal that is prefixed with f or F. This type of string literal allows embedding the results of arbitrary Python expressions within replacement fields, which are delimited by curly brackets ({}).
Find elsewhere
🌐
Real Python
realpython.com › replace-string-python
How to Replace a String in Python – Real Python
January 15, 2025 - As you can see, you can chain .replace() onto any string and provide the method with two arguments. The first is the string that you want to replace, and the second is the replacement. Note: Although the Python shell displays the result of .replace(), the string itself stays unchanged.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Replace Strings in Python: replace(), translate(), and Regex | note.nkmk.me
May 4, 2025 - In Python, you can replace strings using the replace() and translate() methods, or with regular expression functions like re.sub() and re.subn(). Additionally, you can replace substrings at specific p ...
🌐
Tutorialspoint
tutorialspoint.com › python › string_replace.htm
Python String replace() Method
The Python String replace() method replaces all occurrences of one substring in a string with another substring. This method is used to create another string by replacing some parts of the original string, whose gist might remain unmodified.
🌐
Analytics Vidhya
analyticsvidhya.com › home › beginner’s guide to replace() method in python
Beginner’s Guide to replace() Method in Python
April 15, 2024 - In Python, string Replace are immutable sequences of Unicode characters. The `replace()` method is a built-in function that allows you to substitute a specified phrase with another in a string.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › replace.html
replace — Python Reference (The Right Way) 0.1 documentation
>>> "ABCAB".replace('AB', 'ab') 'abCab' >>> "ABCAB".replace('YZ', 'ab') 'ABCAB' >>> "ABCAB".replace('AB', 'ab', 1) 'abCAB' >>> "ABCAB".replace('AB', 'ab', 2) 'abCab'
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-replace-substring-in-list-of-strings
Replace substring in list of strings - Python - GeeksforGeeks
July 11, 2025 - The replace() function replaces all occurrences of "world" with "universe" in each string.
🌐
AlgoCademy
algocademy.com › blog › mastering-python-replace-a-comprehensive-guide-to-string-manipulation
Mastering Python Replace: A Comprehensive Guide to String Manipulation – AlgoCademy Blog
This allows you to replace parts ... more efficient and readable code. Python’s replace() is a built-in string method that allows you to replace all occurrences of a specified substring with another substring....
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-replace
Python String replace() | DigitalOcean
August 4, 2022 - Python string replace() function is used to create a string by replacing some parts of another string.
🌐
freeCodeCamp
freecodecamp.org › news › python-string-replace-function-in-python-for-substring-substitution
Python String.Replace() – Function in Python for Substring Substitution
January 24, 2022 - When using the .replace() Python method, you are able to replace every instance of one specific character with a new one.
🌐
Codecademy
codecademy.com › docs › python › strings › .replace()
Python | Strings | .replace() | Codecademy
June 18, 2025 - In Python, the .replace() method replaces all occurrences of a specified substring with another substring in a string.