Demonstrating Python’s String “replace” Method via the Command-line

Python’s String “replace” method returns a copy of the string in which the occurrences of the old substring are replaced with the new substring. You can optionally restrict the number of replacements to a max amount by adding another number argument to the method call; for example “str.replace(old, new, max)”.

Demonstrating Python's String "replace" method via the command-line

Demonstrating Python's String "replace" method via the command-line


Note that I use the end-of-input indicator for Windows, Ctrl-Z, to signify the end of input from the command-line.
Python output - substring replacement completed

Python output - substring replacement completed

This entry was posted in Programming Languages, Python, Technology and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


two × 8 =