Python Learning notes (i)

Source: Internet
Author: User

Python Learning Notes

1 About Python

Python is an interpreted, object-oriented, dynamic Data type high-level programming language.

1.1 Python Advantages

Compared to other languages, python--class library is full and concise.

Other features: 1. Easy to learn, 2. Easy to read, 3. Easy to maintain, 4. Portable, 5. Expandable; 6. database; 7.GUI programming; 8. embeddable.

1.2 Python types

Cpython, Jyhton, IronPython, PyPy, Rubypython and so on.

2 Python Environment 2.1 Windows

1. Download

2. Installation

3. Environment variables: Right-click computer → properties → advanced system settings → advanced → environment variables.

2.2 Linux

Linux comes with Python; update Linux version steps:

(Linux may require root privileges to install Python using Package Manager!) )

View the default Python version

Python–v
1 1, installing GCC for compiling python source code2 3     Yum Install GCC4 5 2, download source package, https://www.python.org/ftp/python/6 7 3, unzip and enter the source file8 9 4, compiling and installingTen  One./Configure A  -      Make All -  the      Make Install -  - 5, view version -  +/usr/local/bin/python2.7-V -  + 6, modify the default Python version A  at     MV/usr/bin/python/usr/bin/python2.6 -  -     LN-s/usr/local/bin/python2.7/usr/bin/python -  - 7, prevent Yum from executing exceptions, and modify the Python version used by Yum -  in     VI/usr/bin/Yum -  toChange the head #!/usr/bin/python to #!/usr/bin/python2.6 
View Code

3 Python Basics 3.1 python run as 3.1.1 Interactive interpreter 3.1.2 Command line 3.1.3 integrated development Environment 3.2 encoding

The default encoding format in Python is the ASCII format, which fails to print correctly when the encoding format is not modified, so the error occurs when reading Chinese. The workaround is to add #-*-coding:utf-8-*- or #coding =utf-8 at the beginning of the file.

3.3 Notes

One line: # comment

Multiple lines: ' Notes '

(Pycharm shortcut key: ctrl+/)

3.4 PYc File

The bytecode generated automatically after the Python interpreter is compiled.

3.5 variables
A ="Suliuer"b=aPrint("a=%s memory address:%s"%(A, id (a)))Print("b=%s memory address:%s"%(b, id (b))) a="Zhouxiaobin"Print("a=%s memory address:%s"%(A, id (a)))Print("b=%s memory address:%s"% (b, id (b)))

Output (a assignment changes, B still points to the original memory variable ):

A=suliuer memory Address: 6966440

B=suliuer memory Address: 6966440

A=zhouxiaobin memory Address: 11016176

B=suliuer memory Address: 6966440

3.6 Input

Input transforms the appropriate type according to the user input, and if you want to enter characters and strings, you must enclose them in quotation marks, and the raw_input is converted to a character type regardless of the type of user input.

3.7 Flow Control 3.7.1 Conditional statements
if Judging Condition:    Execute statement ... Else :    EXECUTE statement ...
3.7.2 Loop Statement 3.7.2.1 while
 while Judging Condition:    Execute statement ...
3.7.2.2 for
 for inch sequence:   EXECUTE statement ...

The statements in the for ... else:for are no different from normal, while the statements in else are executed when the loop is executed normally (that is, for not breaking out by break), while ... else is the same.

3.7.2.3 Break and Continue

Break: The statement is used to terminate the loop statement;

Continue: Skips the remaining statements of the current loop, and then proceeds to the next round of loops.

#continue and break usagei = 1 whileI < 10: I+ = 1ifi%2 > 0:#Skip output when non-even        Continue    Print(i)#output even 2, 4, 6, 8, tenI= 1 while1:#the cycle condition of 1 must be set    Print(i)#Output 1~10i + = 1ifI > 10:#when I is greater than 10 o'clock jump out of the loop         Break

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.