python backslash as string code example

Example 1: r string python

# a Rstring is a string that treat backslashs as normals caracters
#Exemple:
#normal string
>>> print("This is a line feed : \n and it's usefull!")
This is a line feed :
and it's usefull!
# R-string
>>> print(r"This is not a line feed /n :(")
This is not a line feed /n :(
 
# It's mostly used to write Paths
# Exemple
my_path = "C:\Users\Me\Desktop\MyFile.txt" #Don't works a all but
my_path = r"C:\Users\Me\Desktop\MyFile.txt" #Totaly work!

Example 2: python tab character

Escape Sequence       Meaning
\t                    Tab
\\                    Inserts a back slash (\)
\'                    Inserts a single quote (')
\"                    Inserts a double quote (")
\n                    Inserts a ASCII Linefeed (a new line)

Example 3: python backslash in string

# This will output one backslash
print("\\")
# OUTPUT:
\

Example 4: python escape characters

\'	Single Quote	
\\	Backslash
newline = '\n'