Python's transfer character (study Note III)

Source: Internet
Author: User

Python's transfer character (study Note III)


Escape character \ Can escape many characters, such as \ n for newline, \ t for tab, character \ itself to escape, so \ \ means the character is \, you can print a string in Python's interactive command line to see:

Command:

>>>print ' he\ ' s a boy. '

>>>print ' I\ ' m learning\nlinux. '

>>>print ' \\\n\\ '

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/92/A4/wKioL1kBlGWQJlqSAAAREQcbjqs123.png "title=" 22. PNG "alt=" Wkiol1kblgwqjlqsaaareqcbjqs123.png "/>

If there are many characters in the string that need to be escaped, you need to add a lot of \, in order to simplify, Python also allows to use R ' ' to indicate that the string inside of ' is not escaped by default, for example:

Command:

print ' \\\ ' n\\

Print R ' \\\ ' n\\ #r与引号之间是没有空格的!

:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/92/A5/wKiom1kBl1LRAGS3AAAGstS04Sg674.png "title=" 22. PNG "alt=" Wkiom1kbl1lrags3aaagsts04sg674.png "/>


650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/92/A6/wKiom1kBmtSDoYaWAAAQHa5lU7Q497.png "title=" 22. PNG "alt=" Wkiom1kbmtsdoyawaaaqha5lu7q497.png "/>


    • Extended

If there is a lot of line wrapping inside the string, it is not good to read it in a line, in order to simplify, Python allows "..." format to represent multiple lines of content, for example:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/92/A5/wKioL1kBmdezy6gEAAAOY_4uoQ4192.png "title=" 22. PNG "alt=" Wkiol1kbmdezy6geaaaoy_4uoq4192.png "/>

Note:

Multi-line string ' ... ' You can also add R to the front, so the example above can be written as well.

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/92/A5/wKioL1kBm36g3uLSAAASAk631zE642.png "title=" 22. PNG "alt=" Wkiol1kbm36g3ulsaaasak631ze642.png "/>

This article is from the "Hand of the Paladin Control" blog, please make sure to keep this source http://wutengfei.blog.51cto.com/10942117/1920054

Python's transfer character (study Note III)

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.