Programming language Categories:
Machine language (programming with binary instructions) Advantages: High execution efficiency disadvantage: Low development efficiency, high learning
Assembly language (using English tags instead of binary, essential direct operating hardware) Advantages: High execution efficiency (lower than machine language) disadvantage: low development efficiency, high learning difficulty
High-level languages (use human characters to write programs that must be translated for the calculator to recognize, execute)
1, Compiled type: (c language) the whole translation is similar to Google Translate, compile once can be repeated execution (first translated and executed)
Translation: Program---gcc--machine language execution: machine language---CPU
Advantages: High execution Efficiency disadvantage: Debug program trouble, poor cross-platform
2, interpreted type: (python) translation similar to simultaneous interpretation (side translation side execution)
Program--Interpreter (C language Function "C language interpretation software")--machine language--cpu
Advantages: Easy to debug program, high cross-platform, high development efficiency disadvantage: low execution efficiency
Python program:
Interactive: Debug Programs
Focus: 1, start Python interpreter 2, read the code in the folder into memory 3, explain the execution
Variable:
A mechanism that reacts to a change in state. (Why should there be a variable) the execution of a program is itself a series of state changes.
Define variable variable name = value
Garbage collection mechanism for Python braking (no referenced value)
Increase reference count: x=1,y=x reduce reference count: Del y# Delete reference count
Naming conventions for variables: 1, variable names: letters, numbers, any combination of underscores
2, variable the first character cannot be a number 3, the keyword cannot be declared as a variable name
Define the way; underline, age_f_d=239 (variable name not Chinese, pinyin)
Three characteristics (Heavy) ID of the variable (reaction memory address) type (type) calue (value)
#is; the identity operator (the comparison is the ID) #==; the operation of the value (comparing the value)
Constants: Constant amount Assignment capitalization
The ID is shared when the amount of data is smaller
User-to-Program interaction: input () receives user input and turns input into a string
Comment: Explain code to enhance code readability.
Single-line Comment: # Multiline comment "" "* * *" ""
File Header: #! /usr/bin/env python (only for Liunx)
#-*-Coding:utf-8
Numeric type: int, floating-point number (decimal), float,
String (description) str ("'") supports string concatenation (+ *)
List: defined in the [] number, separated by multiple values (to hold multiple values)
Dictionary: defined in {}, separate each element is Key;vlue (value can say any type, key is not a type of edge)
Boolean type: Judge--ture,false all data types with Boolean values (0,none, empty, false) others are all ture
Mutable type: list, dictionary. Variable value (without changing the ID)
Immutable types: Numbers, strings
Formatted output:%s (character type, number type)%d (character type)
Operator: +-*/(//Go to quotient,% remainder, * * Second Party)
Comparison operation:! = Not equal to
Addition Age=age+1 Age+=1
Logical operations: And logic ' and '; or logic ' or '; not logical ' non '
Identity operation: #is比较的是id值
While: Conditional loop break: Jump out of this layer loop continue: skip this loop and go to the next loop
Python Foundation 2018-3-18