A concise tutorial for Python: Basic concepts

Source: Internet
Author: User

1 literal constants, such as 2, ' This is ok ' such a string

>>> print (' a,2,3 ')

a,2,3


2 string

    • Single quotation mark (')

      Use single quotation marks to indicate a string, similar to a strong reference in the shell, with all the spaces and tabs intact.

>>> print (' This is OK ')

This is OK


    • Double quotation marks (")

      The string in double quotation marks is identical to the string used in single quotation marks

>>> print ("This is OK")

This is OK


    • Three quotation marks ("')

      Using three quotation marks, you can indicate a multiline string, and you can use single and double quotation marks freely in three quotes.

>>> ' This is am am string. The first line.

... The second line.

... "What ' s your name?" Lasked.

... He said "Bond,jamesbond."

' This is am am string. This was the first line.\nthis is the second line.\n "What\ 's your name?" Lasked.\nhe said "Bond,jamesbond."


    • Escape character

>>> ' what \ ' s your name ' #在单引号中实现单引号的使用

"What ' s your name"

or use double quotation marks

>>> "What ' Your Name"

"What ' Your Name"

>>> "This is \" Ok\ "," #双引号中实现双引号的引用

' This is ' OK ', '

Note: The line end is a separate backslash, indicating that the string continues on the next line, such as:

>>> ' This is ok\

..., hello '

' This is Ok,hello '


    • Natural string

      If you do not need a string that is specially handled as an escape character, you can prefix the string with R or R to specify a natural string

>>> R ' New line is by \ n '

' New line is by \\n '



This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1925662

A concise tutorial for Python: Basic concepts

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.