Simple syntax for first knowledge of Python

Source: Internet
Author: User

Grammatical features:

First, the statement is more flexible

No need to declare data type, directly define variable name = variable Value

Ii. Types of data

A variable does not have a data type defined, but it has a data type.

1. Steps for Variables

1) define variable names and assign values

eg: name = ' Zhang San '

Note :

2), there is no semicolon after the statement ";", a line can only write one statement.

3), Python syntax does not have curly braces, by indentation ( The distance of a tab key ) to distinguish the hierarchical relationship between the code

Eg: "If ()

"Print ()

Print () here indicates the output (a variable name can also be output when a variable needs to be output, no print required)

2, the naming specification, and Java Almost, first can not use the key, second can not be used $, class name Capital (Karpasia), function lowercase, variable lowercase start (hump naming)

3, Python case sensitive, the name can not start the number, special symbols can only use "_"

4, How do I know what data type my variable is ? What are the data types?

Know the data type:

Type ( variable name ) Gets the variable memory address function

Id ( variable name ) returns memory address

Python 's memory mechanism:

Edge processing edges reclaim memory, when variables are re-assigned, or useless, memory space is recycled

What are the data types ?

1), String

string conversion function : str ( numeric )

STR string using "" or "package, can be nested with each other

Characteristics

Python 's escape character is the same as Java

"R" refers to a natural string, that is, anything inside a string is executed as a string (either an escape character or something)

String cannot be spliced with numbers

2), Plastic

Int, can only put integers

Most approximately 2147400000

min. approx .-2147400000

3), long plastic

A long integer larger than int

num=-2140000000 until num = 2140000000 is of type int
Starting with num = 2140000001 is the long type

The last number overrides the previous number

4), floating-point type

float, decimal

5), Boolean type

BOOL Type

Ture,false

Three, operator

1, assignment operation:=

arithmetic Operations : +-*/( fetch )%

Dividend divided by divisor = quotient ... . remainder,

Self-operation: no + +,--(only num + = 1,num *= 2,num/= 2,num%= 2,num-= 2)

2, relational operations

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

3, logical operation

and ,or, not

4, power operation

sum = num**4 num 4-Time Square

Eg: "Num=2**4

"Print num

16

Four, Process Control statements

Basic CONDITION Statement:

If condition (bool value) :

Output statement

Else

Output statement

Eg: "score=90

if (score>=85):

"Print" Dad doesn't hit you! ”

"Else:

"Print" Go home to kneel durian! ”

Dad won't hit you!

Five, Python notes

Two kinds of

1) Single-line comment # comment (requires comment class before adding well number)

2) Multi-line comment ' ' annotation ' (need to add three single quotes before and after the comment class)

Simple syntax for first knowledge of Python

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.