Python third-time study notes

Source: Internet
Author: User

The main content of this issue is briefly:
1. Variables;
2. Introduction to the use of escape characters;
3. Raw string usage;
4. Use of long strings;

Detailed Description:

1. Variables: Variables in Python do not need to be declared beforehand, but need to be assigned before use, the variable is more like the label attached to the value, which brings great convenience to Python. The name of the variable is the same as C and the Java programming language, composed of letters, numbers, underscores, and the first is not allowed to be a number, and the variable name is best to be professional, let a person know its meaning.

2. String: In Python, strings are enclosed in double or single quotes, but single and double quotes cannot be mixed. For example, "Small turtle", "calf" is a legal string, and "small beetle" will be an error.

3. Escape character: Just now, in Python, "and?" is the function of defining a string, but if a string itself contains a string, do not hurry, here is our escape character gorgeous debut! The escape character is a backslash ' \ ', and for single or double quotation marks that you want to handle as a character, just precede the escape character. For example, for the string let ' s go!, we can write ' let\ ' go! '. In addition, we can also use "Let's go!" To express. Finally, the escape character plus a letter can represent a special meaning, such as the most common ' \ n ', ' \ t ', and so on.

4. Original string: In Python, the backslash is used primarily as an escape character, and when we need to use its own meaning, it can be preceded by an escape character processing. But for some special strings, if the inside frequently use the backslash, and then manually to add it is cumbersome, this time can be preceded by a letter R, easy to solve, this is the original string meaning, let the string backslash back to the original intent. For example, the string C:\Program file\intel\wifi\help, defined as long as R ' C:\Program File\intel\wifi\help ', his implementation is very simple, that is, the program will automatically add a backslash to each backslash before the backslash. However, R cannot be defined as a string with a backslash at the end, ' C:\Temp\ '. This time if you want to use R for the original string operation can be resolved as follows: R ' C:\Temp ' \ \ ' or R ' C:\Temp ' + ' \ \ '.

5. Long string: In general, use single or double quotation marks only one line of string, if the string is composed of multiple lines, you need to use three

Quotes, for example: "' I love fish C,
As I love the Little turtle.
The sound of his applause and applause,
It always haunts my mind,

Long refused to disperse. ‘‘‘

6. Special Note: All the operators in Python, such as single quotes, double quotes, colons, parentheses, and so on must be English characters, otherwise it will be an error.

0. Naming of variables

The variable should start with an underscore and a letter

1. How does this code appear when not on the computer?

>>> myteacher= ' Little Turtle ' >>> yourteacher = myteacher>>> yourteacher = ' Night ' >>> print ( Myteacher)

Should be showing the little turtle.

2. How does this code appear when not on the computer?

>>> myteacher= ' Little Turtle ' >>> yourteacher = myteacher>>> myteacher= ' Night ' >>> print ( Yourteacher)

Should also show the Little Turtle.

3. How does this code appear when not on the computer?

>>>first = 520>>>second = ' 520 ' >>>first = Second>>>print (first)

An error is displayed: SyntaxError: Multiple statements found in the compilation of a statement

4. In addition to using the \ Backslash for string printing, what method can be printed: let's go! This string

Print ("Let ' s go!")

Always remember the use of the print () function

5. How flexible is it if you want to enter a backslash at the end of the original string?
>>> str = R ' C:\Program files\fishc\good ' \ \ '

0. Use variables to calculate how many seconds a year

>>> dayperyear = 365>>> Hourperday = 24>>> Secondperhour = 60>>> second = Dayperyear*h Ourperday*secondperhour>>> Print (second)

Another way of writing a long string:

>>> string = (
"I love fish c,\n."
"As I love the little turtle, \ n"
"His applause applause voice, \ n"
"Always wrapped in my mind, \ n"
"Long refused to disperse ... \ n")
>>> Print (String) 

Python third-time study notes

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.