Basic concepts of Python syntax

Source: Internet
Author: User
Tags natural string

If you are not familiar with the practical application of the Python syntax, you can use the following articles to give a detailed introduction to the basic concepts of the Python syntax, I hope you will understand some specific applications of computer applications in the following articles.

Although the Python syntax is very concise, I have sorted out some basic points.

Basic Concepts

1. Number: integer, long integer, floating point number example: 3.23 or 52.3E-4, plural: (-5 + 4j) or (2.3-4.4.7 )]

2. String:

1) the strings in double quotes are exactly the same as those in single quotes.

2) using three quotation marks (') or "], you can indicate a multi-line string.

3) Escape Character \], but a separate backslash at the end of a string line is used to continue the line

4) Natural string: The character string is specified by adding the prefix r or R, so that it is not escaped as it is)

5) Unicode string: prefix u or U before the string, for example, u. This is unicode. <o: p> </o: p>

3. variables: when using variables, you only need to assign them a value. No need to declare or define data types

4. identifier: uppercase or lowercase letters), underscore '_', or number 0-9), and the first character must be an uppercase or lowercase letter) or underscore '_')

5. indent: In the Python syntax, statement blocks are marked in indentation instead of braces. That is, statements at the same level must have the same indentation.

6. Operators)

(1) power operator **: x ** y returns the y Power of x. For example, 3 ** 4 = 3*3*3*3*3.

(2) Remove the integer part of the operator //: returns the integer part of the operator. For example, 4 // 3.0 returns 1.0.

(3) Boolean "Non" operator not

(4) Boolean "and" operator and

(5) Boolean "or" operator or

7. Control Flow

(1) if statement: the form is as follows: (Note that the if statement contains a colon at the end, telling the Python syntax to follow a statement block; and there is no switch statement)

 
 
  1. if condition:  
  2. statement  
  3. elif condition:  
  4. statement  
  5. else  
  6. statement   

(2) while statement: the form is as follows:

 
 
  1. while condition:  
  2. statement  
  3. else:  

(3) for statement: the form is as follows:

 
 
  1. for element in collection:  
  2. statement  
  3. else:   

(4) break statement: similar to other languages, it should be noted that if it is terminated from the for or while LOOP, no corresponding loop else block will be executed

(5) continue statement: same as other languages

8. function: defined by the def keyword. The def keyword is followed by the identifier name of a function, followed by a pair of parentheses. Variable names can be included in parentheses, which end with a colon. Next is a sentence, which is a function body, for example:

 
 
  1. def function_name():  
  2. statement  

9. module: a module is a python file. It is generally a tool set or reusable code, similar to the tool class in C.

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.