The outline structure of this note is: Week x--section X (x.x)--one, two, three ...--1,2,3--①,②,③ ...
1.1 Walk into Python
One, Introduction to Python
1 case: Gogle yo tube NASA watercress
2 Design philosophy:
Simple: Ease of use with simple scripting language and interpretive programming language
Clear: Powerful universal functionality in a traditional compiled language
Elegance: Interpretive, object-oriented, high-level programming language with dynamic semantics
3 Past life-founder: Guido van Rossum during Christmas
4 history
Glue language-easy and other annotated programming languages (c/C + +), integrated encapsulation
Scripting language--Advanced scripting language, which can handle simple tasks more powerful than script language
Object-oriented language--completion of support inheritance, overloading, derivation, multiple inheritance
Version 5
Currently there are 2 and 3, a pair of it engineers lovers with 2 and 3, written to write on the break up
This course uses 2, because some libraries only have 2, 2020 end support,
Conversions can be made with 2to3.py
6 Applications
Web Development--python defines the WSGI standard application interface to coordinate the communication between the HTTP server and the Python-based web program
GUI development-using Wxpython or PYQT to develop cross-platform desktop software
7 The Zen of Python
Second, the first Python program
1 case: Classic Hello World
2 How Python works
The ①shell--shell is an interactive interpreter; Enter a single line of commands, and the interpreter interprets the corresponding results.
② File Mode--Create a file with a py extension in the Python IDE environment and run the results in the shell with the Python interpreter
File source
General code snippet short with shell, long with file
③ integrated Environment--scientific calculator python (x, y): IPython, IPython Qt, IDLE, Spider (Visualizer)
3 python output: Print statement
Print Variable: print mysring
Print string: print ' hello,world! '
4 python input: raw_input () statement
Raw_input () The type returned is a character type
5 python style--draw the wind to be beautiful
① notes--#开头直至本行结束, can be in any position
② continuation--\; There are two cases where line breaks are not required: parentheses, brackets, curly braces, and inside of three quotes can be written in multiple lines
③ line multiple statements--;
④ indent-Increases the start of the indent representation statement; Python uses the same indentation to represent the same-level statement block; reduces the exit of the indent representation statement
Iii. Basic of Python Syntax
1 variable variable--variable name: Reference object, identifying object
2 identifier identifier--refers to a valid symbol that is allowed as a variable name or other object name: The first character is a letter or an underscore; the rest can be letters, underscores, numbers, case sensitivity (PI and pi are different identifiers)
_xxx as private, jiage Pinyin also do not use, as far as possible to see name notional
3 keywords-is a key component of the Python language and cannot be used as an identifier for other objects; keywords are basic fixed collections in a language, and often appear in different color fonts in the IDE
4 expression expression--An expression that joins various types of data with an operator
operators have precedence order; Expressions must have an operation result
5 assigns the assignment--variable the first assignment, obtaining both the type and the value. Python is a strongly typed language that is dynamic, does not need to display a declaration, determines the type based on the value, and implements the assignment in a "reference" manner.
Incremental assignment: M%=5 is m=m%5;m**=2 that is m=m**2
Multiple assignments: like a mathematical hyphen
Multivariate assignment: #元组用括号
6 statement sentence--A single line of logic code that executes a task completely; The assignment statement completes the assignment; The print statement finishes the output
Four Date Types of Python--python standard data type: (long) integer, floating-point, plural, string, list, tuple, Boolean, dictionary
1 Integral type int--integral type and long shape are not strictly differentiated; integer value followed by "L" is the long shape; length is -2^31~2^31 or -2^63~2^63
In Python, shaping and long-shaping are unified, related to machine-supported memory, there is no overflow error
2 Boolean-The subclass of an integer, with only two values: True (1), False (0), essentially stored with integer 1 and 0
3 floating-point float--is a real number in mathematics; can be analogous to scientific notation 9.8e3=9800
4 Complex Type complex--j= (-1) ^0.5, then J is an imaginary number; real + imaginary is plural; imaginary part must have J
Complex numbers can separate real and imaginary parts: complex numbers. Real, plural. imag
Conjugation of complex numbers: complex numbers. Conjugate ()
5 sequence Type
① Strings--single quotes, double quotes, three quotation marks (note three three quotes) are all strings, immutable types
Hello's e mystring[1]
② List--powerful type, with [] bounds, mutable type
③ tuples-Similar to lists, with parentheses () bounds, immutable types
6 Mapping type-dictionary; curly braces {} bounds; key-value pairs similar to hash tables
Five Basic operation of Python
1 Arithmetic operations-priority: Powers * *, sign +-, multiplication */, divide//, withdraw%, add minus +-
If the traditional division symbol is integral on both sides, the effect is equally divisible, and the type of the operand is converted to a floating-point type, then it reverts to the traditional division; importing the _future_ package is not necessary, and the built-in clear goose is not like this ...
2 comparison operations-numeric comparisons: By value ratio, string comparison: by ASCII value, result is Boolean
Abc<xyz;3<4<7#same as (3<4) and (4<7) if the C language is 1<7;! = Not equal to
3 logical operators Logical--not, and, or; The result is a Boolean type
4-Character operator-primitive string operator (R/R): For some places where you do not want escape characters to work; Unicode string operator (u/u): Convert to Unicode string
5-bit operators
Six functions,modules and package of Python
1 Functions--functions can be seen as functions similar to mathematics; a piece of code that accomplishes a particular function: Absolute value function abs (x), type function (x), rounding function round (x)
Built-in functions: CMP (), str (), and type () for all standard types
Round rounding
2 Module--A complete Python file even if a module is used, Python often uses the "import module" to reuse functions, classes, etc. from out-of-the-box modules into other code blocks
File: Physical Organization mode math.py
Modules: Logical Organization mode Math
math.py values can be used directly, without the need to define their own
Import module Imports math before non-built-in functions are used
Importing multiple modules: Import ModuleName1, ModuleName2, ...
Module to import the specified module properties, that is, the specified name into the current scope: from Module1 import moduleelement
3 Package package--A hierarchical file directory structure; Defines a Python application execution environment consisting of modules and sub-packages
>>>import AAA. ccc.c1# Package, sub-package, module
>>>aaa. CCC.C1.FUNC1 (123)
Or
>>>from AAA. CCC.C1 Import func1
>>>FUNC1 (123)
4 Library library--Library 11 sets of modules with related functions; one feature of Python is its powerful standard library, third-party libraries, and custom modules
First week Basics of Python into Python