Python learning notes (1) Statements, variables, functions, and python learning notes

Source: Internet
Author: User

Python learning notes (1) Statements, variables, functions, and python learning notes

Today I took the time to read python. It feels good. It is different from a compilation language. C, c ++, java, and c # Are all compiled languages, that is, they must be compiled first, and then

Generate a binary executable file (except java and C #, which can be run only on a virtual machine) at the link, but compilation is also required.

Python is a typical explanatory language. His biggest feature is similar to the scripting language, such as Shell programming, js, and so on, and does not need to be compiled.

Today, I learned the basic syntax of python: Statements, variables, and functions. The following is a summary of the learned content, so that you can learn it in the future.

And Zhixin.

Statement:

First, we will introduce the logical and physical rows of python statements. Physical rows are the actual rows that can be seen in the file. This is the physical line, while the logical line refers to

A semicolon indicates a logical row. A physical row can have multiple logical rows. However, the default rule for python is that a physical row corresponds to a logical row.

Indent: the indentation of python corresponds to the statement block of C. That is, {}. indent is used for if branch, while statement, Function Definition, etc.

Define variables:

You do not need to specify the type for variable definition. Similar to js

Example: length = 10; defines length as an integer variable. There are four types of values: integer, long integer, floating point, and plural. Note that python can define the plural. This and

Many languages are different.

Statement block:

If, while statement block,

If condition:

Statement 1

Statement 2

...

Elif condition:

Statement 1

Statement 2

...

Else

Statement 1

Statement 2

...

 

This is the if syntax.

 

While

 while Condition:

Statement 1

Statement 2

...

else:

Exit statement

 

This is the while statement definition.

 

for Variablein range(Start ValueEnd value):
Statement
else:

Exit statement

 

This is the for loop statement definition. It is equivalent to C's for (variable = start value; variable <End value; variable auto-increment or auto-subtraction) {statement}

 

Function Definition:

Def function name (parameter list ):

Function Block

Note: You can set the default parameters in the parameter list. Similar to C ++;

For example:

def fun(first, second = 1,third = 2): 

Statement Block

It can be called as follows:

Fun (1), 1 will be passed to first

Fun (1, 2), 1 will be passed to first, 2 to second

Fun (1, third = 3), 1 is passed to first, and 3 is an explicit value assignment.

Note: def fun (first = 1, second, third = 3) cannot be defined as the first or second one by default.

Function call:

Fun (1, 1, 2)

 

File Name definition:

The default file Suffix of python is py. You can add the python path to the system variables. This can be called in the command line.

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.