Mike Driscoll
Mike Driscoll

@driscollis

7 Tweets 2 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!

Loading suggestions...