Getting Started with Python base 01

Primer

Based on a learned, with computer hardware, and then install the operating system on hardware, we have a platform to run applications, our next task is to learn how to use a programming language to develop applications under program.

Benpian theme is to bring everyone to understand programming languages, then this highlights the python programming language

The history of programming languages

1, machine language

Pros: fast enough efficiency

Cons: Very low development efficiency

2, assembly language

Advantages: faster execution efficiency, compared to the slower machine language

Disadvantages: low development efficiency, compared to a little faster machine language

3, high-level language

(C, C ++, C #, Java, python, PHP, go, etc.)

Advantages: high development efficiency

Disadvantages: low efficiency

Divided into high-level language compiled and interpreted

Compiled: written instructions compiled into binary code requires the computer to identify, after the operating system will hold compiled binary instructions directly operate the hardware. (Similar to Google translation)

Common languages: C language, C ++, go 

Advantages: compiled once and then you can run repeatedly took the result, without the need to be translated again, the efficiency is higher than the Interpreted

Cons: Compiled Code is a platform for a translation, the translation of the results of the current platform can not get another platform, that can not be cross-platform

Interpreted: similar simultaneous translation, the need for an interpreter, the interpreter reads the program code, while the translation side perform.

Common languages: python, C #

Advantages: dependent on the code interpreter is running, a different version of the platform with a corresponding interpreter, so the code is cross-platform run

Disadvantages: each execution needs to be translated, the efficiency is lower than that compiled

Compared

Development efficiency

(Interpreted> Compiled)> Assembly language> machine language

effectiveness

(Interpreted <Compiled) <assembly language <machine language

Cross-platform

Interpreted> compiled

Learning curve

Machine Language> Assembly language> high-level language

python compiler

Python interpreter What kind?

The official Python interpreter is essentially based on a C-language development software, the software's function is to read the contents of a file ending in .py, and then to translate and execute the appropriate code according to Guido defined syntax and rules. This implemented in C interpreter is called CPython, it is the best python field performance, the most widely used an interpreter, we mentioned at the back of the interpreter are references to the Cpython interpreter. But in fact the interpreter as a software application, can use other language to develop, as long as the interpretation of this language python syntax can be. Some species Python interpreter as follows, simple to understand

 

Jython # 
JPython interpreter is written in JAVA python interpreter, the Python code can be directly compiled into Java byte code and executed, it only makes embedded java python script based on the project possible, but can also be introduced into the java program into the python program. 

IPython # 
IPython is based on an interactive CPython interpreter, that is to say, IPython only been enhanced in the interactive mode, but the execution of the functions and CPython Python code is exactly the same. This is like many domestic browser, although different appearance, but the kernel are actually called IE. 
CPython with >>> as a prompt, and with IPython In [ID]: as a prompt. 

PyPy # 
PyPy is Python developers in order to better Hack Python implemented in Python Python interpreter. PyPy provides JIT compiler and sandbox functionality to Python code is dynamically compiled (note not explained), and therefore run faster than CPython. 

IronPython # 
IronPython and Jython similar, but IronPython Python interpreter is running on the Microsoft .Net platform, Python code can be directly translated into .Net byte code.

pycharm installation and mounting of the python compiler see https://www.cnblogs.com/aheng/p/11754307.html

python version Category:

python2.X (2020 years later will not be updated)

python3.X

python are two ways to execute code

1. Interactive: reciprocal

2, the command line

python file extension defined in the convention .py fact .py is simply a text file (suffix does not matter what, because should use the compiler compiler) does not change as long as the inside source on the right.

IDE tools pycharm

pycharm is dedicated to writing software code, python

Benefits: to enhance the development efficiency

Disadvantages: Comparison of memory resources

Note

As a programmer to develop a good habit to write notes Notes is the mother of Code

Single-line comments: #

Multi-line comments: '' '' '' (double quotes, single quotes may be)

Shortcut keys: Ctrl + /

python variables

 

 

1. What is a variable?

Change: the state of things can change

Capacity: Status Description of things

2, no variable okay

That is certainly not ah

3, how to use variables

Variable names + + variable value assignment symbol

For example: age = 18

Naming variable name

1, only letters, numbers, underscores

2, can not use Chinese (with the Chinese can leave the next day)

3, can not start with a number

4, case sensitive

Named style variable name

1, hump body

For example: UserAge = 18

 

 

2, underscore body

user_age = 18

Three characteristic variables

1, the value of value

2, the address id

3, type type

constant

What is constant?

Constant refers to the amount in the program is running will not change

Why should there be constant?

 During program execution, some values ​​are fixed, and should not be changed, such as 3.141592653 ... Pi

How to use constants?

Not a special syntax for defining constants in Python, the convention is a constant with all uppercase variable names. Such as: PI = 3.14159. So to speak from a single grammatical level, using exactly the same variables constant.

Memory Management

Small integer pool:

id (memory address), except variable name. It is conducive to optimizing the computer's memory. Range (-5-256) outside this range will not be the same as the id address

Garbage collection

1, reference count: the memory when the value of the reference count is zero, the garbage collection mechanism is automatically cleared

2, clearly marked: When the application memory support will automatically stop when full, garbage removal

3, generational recycling: in the case after several scans are not variables are recycled, gc mechanism will think that the variable is a common variable, gc will reduce its frequency sweep, the specific implementation principle is as follows:

Refers to a generational divided according to different levels of variable survival time (i.e. different generations) 

newly defined variable, the new generation into the hierarchy, the new generation is assumed that a scan every one minute, if the variable is still found to be referenced , then the right of the target weight (weight is essentially an integer) plus one, when the variable of weight is greater than a set value (assumed to be 3), it will move to a higher level on behalf of youth, the youth generation gc the new generation is lower than the scanning frequency (longer scan interval), assuming five minutes a scanning young generations, so that the total number of scans required per gc becomes less variable, save the total time of scanning, next, youthful generation of objects, will be moved to the old era in the same way. That is, grade (on behalf of) the higher the lower the frequency of garbage collection scan
Generational recovery

 

Guess you like

Origin www.cnblogs.com/aheng/p/11777166.html