Python history
1989, a Boring Christmas night, Dutch Guido wrote Python, named after his favorite comic name, "Monty Python's Flying Circus."
Python version
2.X developed to 2.7.
3.Xs started in 2008, 3.5 posted on September 2015, 3.6 released in December 2016, 3.7 released in 2018 6 June
2.x and 3.x differences
Statement is functional, such as print 1 2, but 2.x means print statement printing tuple, 3.x meaning is a function of 2 parameters
Divisible, for example 1/2 and 1//2,3.x versions/for natural divide
Raw_input renamed as input in 3.x, no longer used
Raw_input
Round function, the rounding of I.5 in 3.x becomes the nearest even
Unicode for uniform use of strings
Exception capture, thrown syntax change
Programming Basics
-
Program: A set of programs that enable computers to recognize and execute
-
Electronic computers: machines capable of executing programs
-
Two main characters of computer development:
-
Alan Maschiesen. Turing: Known as the father of the computer
-
Von Neumann: one or two binary system for digital computers based on the number of computers in accordance with the program sequence, the computer should have five parts
von Neumann architecture
The computer should consist of five major components:
-
CPU: Composed of operators and controllers
-
operator : complete a variety of arithmetic operations, logic operations, data processing processing, etc.
-
controller : Execution of the control program
-
There are registers and multilevel caches in the CPU
-
: For memory programs and data, such as memory
-
input device : Enter the data cargo program into your computer, such as the mouse keyboard
-
output device : Displays the results of the data-handling process to the user, such as the display, printer
computer language: The language of human interaction with computers
-
Low-level languages: machine-oriented languages, including machine languages, assembly language
-
High-level language: computer language close to natural language and book math language. High-level language first to write the source program, through the compiler program to convert the source program to machine instructions
- High-level and low-level languages need a conversion tool: compiler, interpreter
-
c,c++ The source code for the language needs to be compiled locally
-
Java, Python, C # source code needs , run on a virtual machine
UL class= "List-paddingleft-2" style= "list-style-type:circle;" >
-
Compiled language: CPU instructions for converting source code to target machine
-
Interpreting language: Interpreting and converting to bytecode, running on virtual machine, interpreter executing intermediate code (JVM,PVM)
Unstructured language
Number or label, GOTO, subroutine can be made up of multiple entrances and exits
There are branches, loops
Structured language
Any basic structure allows only the only entry and the only exit
Order, Branch, loop, discard Goto
Object-oriented language
Closer to human recognition, everything is abstracted into objects, relationships between objects are abstracted into classes and inherited
Encapsulation, inheritance, polymorphism
Functional language
Program Programm
- program = algorithm + data structure
Data is at the heart of all Programs
Data structure is the type and organization of the information in the computer
Algorithm is the way of processing data, the algorithm has the advantages and disadvantages of
Notes to write a program
- Clearing data
- Clear Processing method
- Transform the data design into a structure and transform the processing method into an algorithm
- Using the design paradigm to program equipment
- There are bugs in the world program . But it's going to debug .
Python interpreter
-
Official CPYTHON:C language development, the broadest Python interpreter
-
IPython: Called Brother Interactive, enhanced CPython
-
Pypy:python language written Python interpreter, JIT technology, dynamically compiled Python code
-
jython:< The source code for span class= "FONTSTYLE0" >python is compiled into Java bytecode and runs on the JVM
-
Ironpython: similar to Jython, running on. NET platform, Python code is compiled into. NET bytecode
Python basic Syntax (partial)
Escape sequences
Cont.:
Identifier:
Can only be letters, underscores and numbers
Cannot start with a number
cannot be a python keyword, exp:def,class cannot be used as an identifier
Python is case sensitive
Conventions:
Not allowed in Chinese
Not allowed to use ambiguous words, exp:class_
Do not use an identifier that starts with an underscore in python
Constant:
Once the assignment is not tender, change the identifier of the value
Constant literal constants cannot be defined in Python:
A separate amount, such as the "ABC" Variable:
The identifier of the value can be changed after assignment
The language type of Python
Statically compiled language
Dynamic compilation language
No prior life type, can be assigned to other types at any time
It is difficult to infer what type is not known when programming
Strongly typed languages
Weakly typed languages
Original code, anti-code, complement, negative representation
Original code: 5 = 0b101,1 = 0b1,-1 = -0b1,bin (-1)
Anti-code: The inverse code of positive number is the same as the original code, negative number of the anti-code sign bit unchanged, the rest of the bitwise negation
Complement: The complement of positive numbers is the same as the original code, the complement sign of negative numbers is unchanged after +1 (negative complement of complement is the original code)
Negative representation method
Negative numbers are stored in the computer with a complement of 1, with a complement of 1111 1111
5-1 = 5+ (-1) Intuitively is 0b101-0b1, in fact the computer is 0B101+0B111111111.~12 = 13
Expressionsexpression: A combination of numbers, symbols, parentheses, variables, etc.
An arithmetic expression
Logical Expressions
Assignment expression: In Python, assignment is defined , and if a variable is already defined, the assignment is equivalent to redefining the value
Memory management
Garbage collection Mechanism GC
Python programming generally does not care about the survival of variables, generally do not care about memory management
Python records the number of references to all objects using the object reference count
When the object reference number becomes 0, it can be garbage collected by GC
When it comes to performance, you need to consider the reference to the variable, but whether to free up memory or try not to free up memory to see the demand. Exp: the data in this interval cannot be used when the internal release is being sorted
false Equivalent Boolean value, equivalent to bool (value)
1. Empty collection
-Empty string ""
-Empty Ganso ()
-Empty list []
-Empty Dictionary {}
2.None objects
3.0
Python Introductory article