Back to Intellij Community

Warning: Invalid escape sequence '.'

python/python-psi-impl/resources/inspectionDescriptions/PyInvalidEscapeSequenceInspection.html

2025.3-rc-2446 B
Original Source

Reports invalid escape sequences in string and bytes literals.

Starting from Python 3.6, escape sequences that are not recognized (such as \.) produce a SyntaxWarning. In future Python versions, they will become a SyntaxError.

To fix this, you can either escape the backslash (e.g., \\.) or use a raw string (e.g., r'\.').

Example:

# Warning: Invalid escape sequence '\.'
print('\.')

# Correct
print(r'\.')
print('\\.')