Rookie Learn Python first day (installation, programming style)

Source: Internet
Author: User

Python installation

Get Python

1. Official website: www.python.org

2. On any Linux system (recommended, almost all Linux users have installed the system by default Python)

3.PythonXY (interactive comparison), portable Python (green version)

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/9D/F7/wKiom1mJaECzenAAAADTQx6Iimk553.png-wh_500x0-wm_ 3-wmp_4-s_104483854.png "title=" qq picture 20170808152828.png "alt=" Wkiom1mjaeczenaaaadtqx6iimk553.png-wh_50 "/>

A. For Linux systems, it is likely that you have already installed Python in your system. Otherwise, you can install Python through the package management software that came with your release.

B. For Windows systems, installing Python is simply downloading the installer and then double-clicking it.


View version : python-v

two modes of operation : use the interactive interpreter with prompt ; Python code with source file

Python naming:. py


Use the source file Python code to run the pattern :

[Email protected]~/py_training/day1$ VI first_script.py

#!/user/bin/python the first line declares what program to use to run the recommendation #!/user/bin/env python (auto-find path)

# Filename:first_script.py

Print "Hello world! "

Attention:

1.Python is case-sensitive, i.e.printwith thePrintnot the same-note that the previous one is lowercasepthe next one is uppercase .P. Also, make sure that there are no spaces or tabs at the beginning of each line match either-we'll discuss why this is important later.

  2. The first line of that special form of annotations. It is called Organize rows --source file are #!, followed by a program. This line tells you the Linux/unix system when you Execute when your program, it should run which interpreter.

3. any content that is to the right of the # symbol is a comment . Annotations are primarily used as notes for the reader of the program.

[Email protected]~/py_training/day1$ python first_script.py (execution output)

Hello world!

[Email protected]~/py_training/day1$ chmod 755 first_script.py (or run as executable)

[Email protected]~/py_training/day1$ ls

first_script.py

[Email protected]~/py_training/day1$./first_script.py ( with./to indicate that the program is in the current directory )

Hello world!

Attention:

If you remove the #! under executable operation, /user/bin/python will error, remind do not know what program to execute, default shell execution, so use: #!/user/bin/env python

Comments:

$ is the shell prompt. Depending on the settings of your operating system, it may be different from yours, so I only use the $ notation to indicate the prompt.

Python Programming style

First, the grammar requirements

1. Indentation Unification

2. Variables (recommended variables are popularized, such as My_name or myname)

The first character of the identifier must be the letter in the alphabet (uppercase or lowercase) or an underscore (_);

Other parts of the identifier name can consist of a letter (uppercase or lowercase), an underscore (_), or a number (0~9);

The identifier name is case-sensitive. such as MyName and MyName not with an identifier;

Examples of valid identifier names are I, _my_name, name_123, or a1b1_c3;

Examples of invalid identifier names are 2things, My-name, or this was spaced out;

Second, the operation

1+1*3/2

2**32 (2 of 32 Parties)

10%3 (modulo/seek remainder, simple use: Display a different color for each column)

A=14

B=12

A>b a<=b A!

Assign value

User_name= ' Carlos '

Age=27

Next_year_age=age+1

Third, comments

1. Single-line Comment #

2. Multiline comment ' Ahfhlkajkfajkfka ' or

"" "Ahfhlkajkfajkfka" ""

Print "My name ' s CARLOS"

print ' My name ' s CARLOS '


Rookie Learn Python first day (installation, programming style)

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.