Python .escape()

design2461360801's avatar
Published Jun 25, 2022Updated Oct 13, 2023
Contribute to Docs

The .escape() method returns a modified string with all special characters escaped and included in the pattern match.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Syntax

glob.escape(sequence)

Any special characters in the sequence will be placed in brackets. This includes the opening square bracket [.

Codebyte Example

The following example showcases the .escape() method and highlights each special character:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours