Replace method
A replace operation substitutes selected matching content or values with specified alternatives in a string, collection, or other object, either returning a result or modifying the object.
The Quick Python Book, Fourth Edition
replace is a Python string method that returns a copy with occurrences of a specified substring replaced by another string, optionally limiting the number of replacements.
- How it is used
- Supports substring substitution and punctuation removal before splitting text into words.
- How deep it goes
- Defines the two required arguments and immutable return value, but defers details of the optional third argument to documentation.
- Examples
- Shows `ss` replaced in `Mississippi` and periods and commas removed from lowercased file text.
- What you can do after
- Practice/perform substring substitution and basic text normalization while choosing translate for numerous character substitutions.
Read how The Quick Python Book, Fourth Edition explains replace method →
Graph Algorithms for Data Science
The Cypher replace function returns a string formed by replacing occurrences of a specified substring with another string.
- How it is used
- Cleans tweet text and normalizes hashtag tokens before splitting, filtering, counting, or storing extracted tags.
- How deep it goes
- Defines the three-argument syntax and demonstrates two practical replacements, but does not develop replacement semantics beyond basic usage.
- Examples
- Uses newline cleanup and comma removal while extracting hashtags from non-retweet tweets.
- What you can do after
- Apply it via Cypher to normalize strings inside a text-processing query.
Read how Graph Algorithms for Data Science explains replace method →
Secrets of the JavaScript Ninja, Second Edition
A JavaScript String method that returns a new string with matched text replaced by specified text or text produced by a callback.
- How it is used
- Replaces regular-expression matches with fixed text or callback-generated text.
- How deep it goes
- Explains global matching and callback arguments with worked examples, without detailing implementation internals.
- Examples
- Demonstrates uppercase substitution, camel-case conversion, and query-string compression.
- What you can do after
- Apply String.replace() with regexes and callbacks to transform matched text or process repeated matches.
Read how Secrets of the JavaScript Ninja, Second Edition explains replace method →
100 Java Mistakes and How to Avoid Them
The Java String.replace method returns a string in which matching occurrences of a target character or sequence are replaced with a specified replacement character or sequence.
- How it is used
- Applies literal substring replacement while preventing regex-related and expression-precedence mistakes.
- How deep it goes
- Explains literal matching, replacement scope, precedence failures, regex hazards, and static-analysis assistance through focused examples.
- Examples
- Uses multiline HTML templates, user placeholders, literal usernames, and regex replacement-group failures.
- What you can do after
- Diagnose ineffective replacements and select replace(), replaceAll(), or replaceFirst() according to matching and replacement requirements.
Read how 100 Java Mistakes and How to Avoid Them explains replace method →
Get Programming: Learn to code with Python
replace is a Python string method that returns a string with occurrences of one substring substituted by another substring.
- How it is used
- Revises text by substituting every occurrence of one substring with another.
- How deep it goes
- Demonstrates the two-argument form with worked replacements and quick checks, without descending into implementation details.
- Examples
- Uses spaces, letters, removed substrings, punctuation, and translated words as replacement examples.
- What you can do after
- Apply it via Python to replace, remove, or revise matching substrings in a string.
Read how Get Programming: Learn to code with Python explains replace method →
Related concepts
- Mapuses · A map is an associative data structure that stores key-value pairs and supports retrieving values by key.
- regular expressionuses · A formal pattern notation that describes sets of strings and enables text to be matched, searched, extracted, or transformed.
- translatealternative to · str.translate is a Python string method that returns a copy with characters transformed or deleted according to a translation table.
- functionuses · A function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
- substringuses · A substring is a contiguous sequence of characters contained within a larger string or character sequence.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




