Hướng dẫn dùng backslash python python
Summary: in this tutorial, you’ll learn about the Python backslash character as a part of a special sequence character or to escape characters in a string. Introduction to the Python backslashIn Python, the backslash( For example, the Generally, the backslash has two main purposes. First, the backslash character is a part of special character sequences such as the tab character The following example prints a string that has a newline character:
Output:
The \n is a single character, not two. For example:
Second, the backslash
(
Output:
Backslash in f-stringsPEP-498 specifies that an f-string cannot contain a backslash character as a part of the expression inside
the curly braces The following example will result in an error:
Error:
To fix this, you need to join the strings in the
Output:
Backslash in raw stringsRaw strings treat the backslash character (
Output:
Summary
Did you find this tutorial helpful ? |