Home > Backend Development > Python Tutorial > What is a string? (2) Escape characters and operators

What is a string? (2) Escape characters and operators

乌拉乌拉~
Release: 2018-08-14 15:53:40
Original
1693 people have browsed it

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:

What is a string? (2) Escape characters and operators

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":

What is a string? (2) Escape characters and operators

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'
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template