"Py" variable, string, raw string, long string

Source: Internet
Author: User

Variable:

Variables in Python do not need to be declared beforehand, but need to be assigned before they are used, in the same way that other programming languages consist of letters, numbers, underscores, and the first cannot be numbers

String:

Python is enclosed in double or single quotation marks, but single and double quotes cannot be mixed, such as if the string itself contains a string, you can use the escape character

Let's go! two ways of writing:

1 ' let\ ' s go! ' 2 " Let ' s go! "
1 " Let ' s go! " 2 " Let ' s go! "
Original string:

When you want to use the backslash's own meaning, you can add a backslash to the front to escape character processing

1 Print ("c\\desktop") 2 C\desktop

However, for some special strings used frequently to backslashes, you can add a letter R in front of the string, you can easily solve

1>>>Print('C:\Program file\ntel\wifi\help')2 C:\Program File3 Tel\wifi\help4>>>Print('C:\\Program File\\ntel\\wifi\\help')#using escape character processing5 C:\Program file\ntel\wifi\help6>>>Print(r'C:\Program file\ntel\wifi\help')#using raw string processing7C:\Program File\ntel\wifi\help
Long string:

You can use single or double quotation marks to enclose only one line of string, if the string consists of multiple lines, you need to use three quotation marks

1>>>" "I love fish C,2 as I love the Little turtle. 3 The sound of his applause and applause,4 It always haunts my mind,5 Long refused to disperse. " "6 'I love fish c,\n as I love the Little turtle. \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Applause, applause. '7>>>Print(" "I love fish C,8 as I love the Little turtle. 9 The sound of his applause and applause,Ten It always haunts my mind, One Long refused to disperse. " ") A I love fish C, - as I love the Little turtle.  - The sound of his applause and applause, the It always haunts my mind, - Long refused to disperse.  

"Py" variable, string, raw string, long string

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.