Home >Backend Development >Python Tutorial >What is a string? (2) Escape characters and operators
In the previous article, we learned about python strings, and how to use some strings, and learned how to intercept python strings and update and modify characters. string. These are relatively simple string processing methods. Next, we will continue to understand and learn about strings.
python escape characters: When special characters need to be used in characters, python uses backslash (\) to escape characters. See the table below for details:
Next let’s take a look at python string operators:
First we first To define The value of instance variable a is the string "Hello", and the value of variable b is "Python":
There are not very many operators, and You can follow the table above to understand and become proficient.
Next, let me give some examples to demonstrate:
#!/usr/bin/python # -*- coding: UTF-8 -*- a = "Hello" b = "Python" print "a + b 输出结果:", a + b print "a * 2 输出结果:", a * 2 print "a[1] 输出结果:", a[1] print "a[1:4] 输出结果:", a[1:4] if( "H" in a) : print "H 在变量 a 中" else : print "H 不在变量 a 中" if( "M" not in a) : print "M 不在变量 a 中" else : print "M 在变量 a 中" print r'\n' print R'\n'
The results of the above examples are as follows:
a + b 输出结果: HelloPython a * 2 输出结果: HelloHello a[1] 输出结果: e a[1:4] 输出结果: ell H 在变量 a 中 M 不在变量 a 中 \n \n
In this article, we understand Python escape characters and Python string operators not only list two tables to assist learning but also demonstrate some examples to aid understanding. Python strings are a very practical thing to learn, and you'll find yourself able to use them in many situations. Finally, I hope this article can bring some help to you who are learning python.
For more related knowledge, please visit the Python tutorial column on the php Chinese website.
The above is the detailed content of What is a string? (2) Escape characters and operators. For more information, please follow other related articles on the PHP Chinese website!