This article mainly introduces the information about the left and right slashes (forward and backward slashes) in Python, which is very good and has reference value, for more information about the left and right slashes (forward and backward slashes) in Python, see this article, for more information, see
">
First, "/" is a forward slash and "\" is a backslash. it can be recorded as a forward slash. In general, a forward slash/is used for directory separators, and Unix and Web /, windows uses a backslash, but now Windows
(1) slash in the directory
The directory parameters that need to be input for reading python files. the following examples are listed:
Path = r "C: \ Windows \ temp \ readme.txt"
Path1 = r "c: \ windows \ temp \ readme.txt"
Path2 = "c :\\ windows \ temp \ readme.txt"
Path3 = "c:/windows/temp/readme.txt"
The parameters in open () can be path, path1, path2, or path3.
Path: "\" is a special character in the string. if r is added to the original string, "\ t" and "\ r" in the string are not escaped.
Path1: Case sensitivity does not affect file location in windows
Path2: cancels the special escape function of the second "\" with a "\", that is "\\"
Path3: Directory separators can also be converted to the corresponding directory by using a forward slash, and the path3 method in python saves the troubles of backslash \ escape.
(2) slashes in regular expressions
The regular expression matches the backslash "\". why is it "\" or r?
Because \ is a special symbol in a regular expression, in order to cancel its special meaning in a regular expression, you need to add \ to become \, but the problem comes again, \ is also a special character in the string, so it must be canceled for both \, that is \\\\. In Python, there is an original string operator used for special characters in the strings. in the original strings, there are no escape characters or printable characters. In this way, the escape function of \ in the string can be canceled, that is, r "\\".
The preceding section describes how to use the left and right slashes (forward and backward slashes) in Python. For more information, see other related articles in the first PHP community!