Mike Driscoll
Mike Driscoll

@driscollis

7 tweets 5 reads Jan 28, 2023
Today I want to talk about #Python's special escape characters
Join me in another fun thread!
πŸ§΅πŸπŸ‘‡
Here is a list of the most common escape characters in #Python
🐍 \n - ASCII Linefeed or Newline
🐍 \t - Horizontal tab
🐍 \r - Carriage return
🐍 \b - Backspace
🐍 \f - Form feed
🐍 \' - Single Quote
🐍 \" - double quote
🐍 \\ -Backslash
🐍 \v -vertical tab
One of the most common escape characters in #Python is `\n` or the line feed character.
Line feed is not printable. It basically tells Python to add a newline on the end of your string.
The line feed is useful for formatting your output. You can add more than one too!
Another common escape character in #Python is `\t` or the tab character
You can use `\t` to add one or more tabs in your strings
`\r` used to be used on old versions of Mac OS as a carriage return.
`\n` is used on current Mac and Linux for new lines
`\r\n` is still the standard on Windows for new lines as far as I know
Technically, they all represent the end of a line
stackoverflow.com
I have rarely had a need for the other escape characters except in weird edge cases where I needed to escape a backslash on Windows
I hope you've enjoyed this little foray into #Python escape characters.
Follow me for more fun tips on the Python language!

Report this thread