Today is the first day of learning Python courses, mainly from the computer base, Python's history, environment variables, constants, comments, user interaction, basic data types, simple conditional statements and if these statements while loop to learn, focus master the content is a python environment, as well as python2 and python3 difference, constants and so on. ,
1. Computer Basics
cpu: equivalent to the human brain, for the calculation.
Memory: data storage, there are 4G, 8G, 16G, 32G, 64G high cost, power will disappear.
Hard disk: 1T, solid state drives, mechanical drives, data storage, should be long-term preservation of data and important documents.
2.Python history
In general:
Python2 and Python3 difference:
Python2 source is not standard, confusion, more duplication of code.
Python3 unified standard, removing duplicate code.
3.Python environment (*)
Compiled: all-time compiled into a binary file.
Disadvantages: low efficiency of development can not be cross-platform
Advantages: run fast
For example: C, C ++
Interpreted: When the program executes, line by line explanation.
Advantages: development of high efficiency, cross-platform
Cons: Slow speed
For example: Python, Php
4. Run the first .py file
python3x: python file path Enter
python2x: python2 file path Enter
python2 python3 difference:
python2 default encoding is ascii code
solution:
in the first line of the file: # - * - encoding: UTF-8 - * -
python3 default encoding utf-8
5. Variables
Variable: some intermediate result of the operation is temporarily stored into memory, the subsequent code to invoke.
Use variable requirements:
1, must be numbers, letters, underline any combination thereof, and can not begin with a number.
2, can not be a python keywords.
[ 'and', 'AS', 'Assert', 'BREAK', 'class',' Continue ',' DEF ',' del ',' elif ',' the else ',' the except ',' Exec ',
' finally ',' for ',' from ',' global ',' if ',' import ',' in ',' is', 'lambda', 'not', 'or', 'pass',' print ' , 'The raise', 'return', 'the try', 'the while', 'with', 'the yield']
. 3, has a descriptive variables.
4, can not be Chinese.
6. Constant (*)
Constant: convention, can not be changed, all uppercase.
eg.
BIR_OF_CHINA = 1999
7. Notes (*)
Note: to facilitate their easy for people to understand the code.
1. Single-line comments: #
2. Multi-line comments: 1) '' is the annotation content '' '2) "" "annotation content is" ""
8. The user interaction (*)
User interaction: input ·
1. Wait for input
2. Place the contents of your input is assigned to the front of the variable.
3.input out all data types str
9. The basic data types
1. Digital: 12,3,45 int
+ - * / **
% I fetch
ps: type ()
string into digital: int (str) Condition: str must be numbers.
It is converted into a digital string: STR (int)
2. string: str, python all of which are caused by the string in quotation marks.
Additivity: string concatenation.
Can be multiplied: str * int
3.bool: Boolean value. True False.
10. if
official:
if conditions:
result
11.while
1) official:
while conditions:
Loop (- infinite loop> loop may occur)
2) how to solve the infinite loop problem?
1. Change the conditions, it is not established
2. break, end of the cycle
12.continue
continue: the end of this cycle, the next cycle continues.