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

Source: Internet
Author: User
In the previous article, we learned python string, and know how to use some strings, learn how to do python string interceptionand update the modified string. These are some of the more simple ways to handle strings, and then we continue to learn about them.

python escape character: Python uses a backslash (\) to escape characters when special characters are required in characters. See the table below for details:

Now let's look at the python string operator :

First we first define the instance variable a value as the string "Hello" and the B variable value to "Python":

The operator is not very much, and can be understood and skilled according to the table above.

Let me give you some examples to illustrate:

#!/usr/bin/python#-*-coding:utf-8-*-a = "Hello" b = "python" print "A + B output result:", A + b print "A * 2 output:", A * 2 pri NT "a[1] Output:", a[1] print "a[1:4" output: ", A[1:4]  if (" H "in a):    print" H is in variable a "else:    print" H is not in variable a "  if ("M" Not in a):    print "M is not in variable a" else:    print "m in variable a" print r \ n ' Print R ' \ n '

The result of the example above is as follows:

A + B output result: Hellopythona * 2 output: hellohelloa[1] Output result: ea[1:4] Output: ELLH in variable A is not in variable a \ n

In this article, we learned about the Python escape character and the Python string operator, which not only lists two table-assisted learning but also demonstrates some of its examples to help understand. Python strings are a very useful point of knowledge and you will find yourself able to use them in many situations. Finally, I hope that this article will give you a little help in learning about Python.

For more information, please visit the PHP Chinese Web Python tutorial section.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.