python second to fifth chapter study notes

# 2 - Chapter 5 Study Notes

## What is the computer language
computer is a machine used a computer, let the computer do the computer people have to do!
The need to control computer (programming language) by the language of the computer!
In fact, computer language and human language is not essentially different, the main difference is that different communication!
Computer language has gone through three stages: the
machine language
- written in machine language program through binary encoding
- good execution efficiency, write too much trouble

Sign language (Assembler)
- use of symbols instead of machine code
- the preparation process, without the use of binary, but directly written symbols
- after completion, the need to machine code symbols into, and then executed by the computer
symbols into machine code the process is called assembler
- converted to machine code symbol process, called the disassembly
- assembly language is generally available only for certain hardware, poor compatibility

High-level language
- basic and high-level language syntax English-like syntax now, and the hardware and the relationship is not so close
- that we can perform in different hardware systems through high-level language development program
- and it is also high-level language learning more easy, now we know the language are basically high-level languages
- C, C ++, C # , Java, JavaScript, Python. . .

## compiled languages and interpreted languages
computer only recognizes the binary coding (machine code), so any language must first be converted to machine code execution when handed over to the computer,
which is like print ( 'hello') will need to be converted this is similar to machine code 1010101

Depending on the timing of the conversion, the language is divided into two categories:
compiled languages
- C language
- compiled language, the code will be executed before the code is compiled to machine code, machine code and then handed over to the computer to perform
- a (source) - - compile -> b (compiled machine code)
- features:
perform very fast
cross-platform poor

Interpreted language
- the Java Python JS
- interpreted language, the code is not compiled before execution, but while compiling execution while at the same time executed
- a (source) - Interpreter -> interpreted
- Features:
execution slower
cross-platform better

## Python Introduction
Python is an interpreted language

Python (English pronunciation: / paɪθən / American pronunciation: / paɪθɑːn /), is a widely used high-level programming language, belonging to general-purpose programming language created by Guido van Rossum, the first edition published in 1991. It can be regarded as a modified (addition of a number of advantages in other programming languages, such as object-oriented) in LISP. As an interpreted language, Python's design philosophy emphasizes readability and concise syntax code (particularly the use of spaces to indent a block of code division, instead of using braces or keywords). Compared to C ++ or Java, Python allows developers to express the idea with less code. Whether small or large programs, the language structure of the program are trying to make clear.

Life is short you need Python (Life is short, I used Python)

Python uses:
the WEB application
Facebook watercress. . .
Crawler
scientific computing
automation operation and maintenance
of large data (data cleansing)
cloud computing
desktop software / game
AI
. . .

## Python development environment to build
the development environment to build is to install the Python interpreter
Python interpreter Category:
CPython (official)
with c language Python interpreter
PyPy
in Python language Python interpreter
IronPython
written in .net Python interpreter is
Jython
written in Java Python interpreter

Step:
1-3.6.5.exe download the installation package python
- 3.x
- 2.x
2. Installation (fool mounting)
3. Open a command line window, enter the following occurs python
Python 3.6.5 (v3.6.5 : f59c0932b4, 28-Mar 2018, 16:07:46) [v.1900 the MSC 32 'bit (the Intel)] ON Win32
the Type "Help", "Copyright", "Credits" or "License" for More Information.
>>>

## Python interactive interface
when we enter the command line Python, the interface is entered into the Python interactive interface
structure:
the version and copyright notice:
Python 3.6.5 (v3.6.5: f59c0932b4, Mar 28 2018, 16:07 : 46 is) [v.1900 the MSC 32 'bit (the Intel)] ON Win32
the Type "Help", "Copyright", "Credits" or "License" for More Information.

Command prompt:
>>>

At the command prompt, you can enter Python commands directly! Enter the complete command will be executed immediately Python interpreter!

Python installed, it will automatically install a Python development tools IDLE, IDLE can also enter through the interactive mode
but the difference is in the IDLE precautionary statements can be viewed through the TAB key.
IDLE is actually an interactive interface, but he can have a few simple tips, and you can save the code

Interactive mode you can only enter a line of code, it is one line, so he does not apply to our daily development!
Can only be used to do some daily simple test!

We generally will write Python code to a py file, and then execute the code file through python command

Exercise:
own py try to create a file and write python print statement (print ...) file
and then execute the file.
If your extension system can not be modified, try yourself baidu!

## Python and Sublime integration
1. Run the Sublime in Python code, ctrl + b Sublime performed automatically in the built-in console in
this implementation, the Chinese support is not good in some versions of Sublime, and you can not use input ( )function

2. SublimeREPL python code to run the
installation is complete, set the shortcut keys, desired current is automatically performed by f5 Python code
{ "keys": [ "f5 "], "caption": "SublimeREPL: Python", "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config / Python / Main.sublime-menu"}},

## concepts
1. The expression
expression is something similar to a mathematical formula
such as: 10 + 58--4
expressions are generally only used to calculate some of the results, will not have a material impact on the program
if the interactive mode enter an expression, the interpreter will automatically output the result of the expression

2. The statement
statement in the program generally need to complete certain functions, such as printing information, access to information, assign values to variables. . .
For example:
Print ()
INPUT ()
A = 10
statement execution procedure will generally have a certain impact
will not necessarily output results of a statement in interactive mode

3. Program (program)
program is a one of the statements and expressions one by one made of.

4. The functions (function)
function is a kind of statements, functions designed to perform specific functions of
the function as a long form: XXX ()
classification function:
Built-in functions
- Python functions provided by the interpreter can be used directly in Python
custom functions
- functions independent programmer created
when we need to complete a certain function, you can go to call built-in functions, custom functions or
two elements of function:
parameters
- content () is the function of the parameters
- parameter can not function, there may be a plurality of parameters, among a plurality of parameters, spaced
return value
- the return value is a function of the result, not all of the functions return the value of
## basic syntax
1 in Python strictly case-sensitive
each line is 2.Python in a statement, wrap each statement to end
3.Python each line statement not too long (recommended specification of each line not more than 80 characters)
"the Rulers": [80] ,
4. a statement can be written in multiple lines, the preparation of multi-line statement back to \ end
5.Python is indented strict language, so do not just write in Python indentation
6. use # in Python Indicates a comment, the contents belong to # comments, the contents of the comment will be ignored by the interpreter
that we can come to an explanation by program notes, we must develop good habits of writing comments
comments requiring a simple and clear, the general practice It will be followed by a space behind #


## literals and variables
literals a is a value, such as: 1,2,3,4,5,6, 'HELLO'
meaning indicated literal is its literal value can be directly used in the program literals

Variable (variable) can be used to store variables literals, variables and literals are stored indefinite
variable itself has no meaning, it can mean different things depending on the literal

Generally, we in the development, rarely used directly literals are saved literal to a variable, the variable is referenced by literal

## variables and identifiers
## data type
data type refers to the type of a variable worth, that is, which values can be assigned to a variable
value
int
Boolean value
float
complex
string
null

## type checking
## objects (Object)
- Python is an object-oriented language
- everything is an object!
- running them, all data is stored into memory and then run!
- the object is designed to store in memory the data of a specified area
- in fact, the object is a container designed to store data
- as before we learn values, strings, Boolean values, None are objects
- with reference to FIG. 1

Structure ## objects
- each object must hold three types of data
- id (identity)
> the above mentioned id used to identify the object is unique, each object has only the above mentioned id
> object is equivalent to the above mentioned id identity cards No. Like
> by id () function to see the object id
> id is generated by the parser, in the CPython, is the memory address of the object id
> object once created, its id can never be changed

- type (Type)
> type is used to identify the type of the current object belongs
> For example: int str float bool. . .
> Object type determines which functions
> by type () function to see the type of object
> Python is a strongly typed language, the type of the object can not be modified once created


- value (value)
> is a specific value of data stored in the object
> value for some objects may be changed
> object into two categories, mutable objects immutable object
value of the variable objects can change
the value of immutable objects can not be change, before learning objects are immutable objects
- 2 with reference to FIG.

Exercise: Try to paint himself at the memory structure of the object.

## variables and objects
- the object is not directly stored in variables, variables in Python is more like an alias to the object from
- the value stored in the variable is not an object, but id (memory address) objects,
when we when using variables, in fact, to find objects by id in the object
- an object stored in a variable, the variable only when re-assignment will change
- is between independent variables and variables, modify a variable does not affect the other variable

- 3 with reference to FIG.

## type conversion
- so-called type conversion, to convert an object of type for other objects
- type conversion not change the type of the object itself, but creates a new object based on the current value of the object

## operator (operator)
- arithmetic operators may be one or various operations value or values
- such as +, -, = belong operator
- classification operator:
1. arithmetic operator
2. Assignment operator
3. comparison operators (relational operator)
4. logical operators
The conditional operator (ternary operator)

Guess you like

Origin www.cnblogs.com/mylive/p/12537453.html