Python Learning Notes (i)

Source: Internet
Author: User

Why learn python? Because Python is so much more useful.

I want to learn a language to maintain the good, but recently Python is too hot, what artificial intelligence, web crawler, and the society, thinking more learning something is always good, so the time to learn the next.

This article does not have any technical reference, may also have a lot of typos, this article only is I learn the Python language the accompanying note.

The system environment for the Linux,python version is 3.4.

How do I write code?

Two ways to write code in Python

1. Create a new file with VI, then write the Python code in it and execute it in Python when the code is entered. If I use VI to create a file for test.py, enter the correct Python code inside, and finally execute

$ python3/home/ser/test.py

2.Python Shell, this mode is like a Linux shell to lose, can enter any code. In contrast to the Linux shell, the Python-supported code and specifications are entered in the shell, and when the instructions are entered, press ENTER to execute.

Note: When you enter $ python3 in the command, there is no parameter appended to the Python Shell mode, when you enter $ python3 in the command./test.py means to execute test.py this file

During my studies I basically used a Python Shell, unless special cases were written to the file.

Python is not compiled to execute the language, like PHP, JavaScript, I called the scripting language, I do not know whether the title is correct.

The special point of Python syntax

The first time I touched Python, I felt a strange grammar. Other languages the end of a statement is to add a semicolon after the statement; Pyhon is not the case, the end of the Python line is to hit the Enter button after the statement, and this is the end. The following is the difference between Python and PHP statements

Python statement

Print ("Hello python")

PHP statements

<? PHP Echo "Hello php";? >

The end block of the Python statement is also very special, such as C or PHP, a statement block is wrapped in curly braces, and Python is the colon +tab key indentation form, the code form is as follows

if age >=    :print(" adult ")Else    Print(" underage ")    print(" no entry, you should go back to school and study well. " Print (" I don't have this if indent, so I don't belong to the If block's content oh ")     

Python defines a variable, the variable name is left when the variable is defined, followed by the assignment of the variable. Python is also a weakly typed language, so you don't have to define a type

C Voice

int a=; Char b='b'; float c=1.2

Big Python does not need this, he is very much like the definition of PHP, as follows

Name =" xiaoming "=20= 182.6

In writing code, it is often important or not easy to understand the place to add comments, Python notes there are 3 kinds of

1. Comment on the pound sign

2. appear in pairs with 3 single quotes

3. Appear in pairs with 3 double quotes

Python's annotated form is as follows

#Age (Hey, I'm just a comment)#I belong to a single line commentAge = 12" "name, haha I belong to multi-line Comment Oh the beginning and end of the note with 3 quotes I ... Ha ha....... " "name="Wong Choy""""sex, GG, how? I am also a multi-line comment oh, wonderful. Note the beginning and end of the note with 3 double quotes, it must be in 3 pairs, do not start with double quotes, and end with single quotes"""Sex="male""""I can also annotate a single line of"""" "of course, I can also annotate a single line" "

Python Learning Notes (i)

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.