(i) Basic Python syntax

Source: Internet
Author: User

1. Comments

Start with #

2. String

The data type is str type;

Enclosed in double quotation marks "" or single quotation marks, if the string contains characters, the ' This is a ' string ' format

3. Number

There are only two types of int and float type.

The accuracy of the flaoat type is approximately 15 bits after the small tree point.

4. Operators

5 Basic operators: + 、-、 *,/,**

Modulo operation:%

The divisible operator://returns the truncated integer.

5. Method (function)

(1) The format is as follows

def method name ([parameter 1],[parameter 2] ...):

Method body

Return

(2) Description:

A. Method names are named in the same variable name format, parameters can be either not, or by multiple

B. Method name followed by ":"

C. A method body is represented by a character indent.

D. Each method has a return value, and if no return is written in the method, the default return is None (return none)

6. Import keyword

Introducing Libraries

7. Boolean type (bool) and logical operator

BOOL Type: TRUE, False

Logical operators: And,or,not

8. Relational operators

==,!=,>=,<=,>,<

9. Conditional statements

if (bool value):

Program block

Elif (bool value):

Program block

Elif.

Else

Program block

Tips

1, the '//' operator is not rounded, to be rounded, use the round () function.

2, the use of modulo operation: can deal with circulation problems, such as snake game (snake into the right edge from the left side of the border out), circular clock problems (from the current point of time, the time of the hours after the request)

3. The blocks in Python are identified by character indentation.

(i) Basic Python syntax

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.