Marten
0
Q:

r string python

#A raw string considers backslash as literal instead of an escape character
print(r"C\Users\MyName\Desktop")
#Without the r in front you will have to escape the \ with another \
print("C\\Users\\MyName\\Desktop")
#Both will print the same thing "C\Users\MyName\Desktop"
4
# 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!
1

New to Communities?

Join the community