Answers for "backslash in python"

9

backslash in python

In python a backslash is used a an escape character, if you want to
include a tab, newline, quote or any unicode character, you must use a
backslash.

'\'' - quote
'\"' - double quote
'\n' - newline
'\t' - tab
'\r' - carriage return
'\\' - backslash
'\u...' - unicode character (replace ... with the corresponding 4-digit number)
'\b' - backspace
'\f' - form feed
'\ooo...' octal value (replace ...)
'\x..' hexadecimal value (replace .. with two characters)
Posted by: Guest on April-07-2021
11

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!
Posted by: Guest on June-22-2020
4

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)
Posted by: Guest on September-18-2020
1

python print single backslash

print('\\')
Posted by: Guest on August-17-2020
1

python backslash in string

# This will output one backslash
print("\\")
# OUTPUT:
\
Posted by: Guest on February-07-2021

Python Answers by Framework

Browse Popular Code Answers by Language