1. First knowledge of computers. CPU memory, hard disk, operating system
CPU: Brain, central processing Unit, Computing center.
Memory: Temporarily stores data for CPU operation.
Advantages: Fast reading speed.
Disadvantages: Small capacity, high cost, power loss disappears.
Hard disk: Long-time storage of data, large amounts of data. 500G,1T,2T, big movies, small videos.
Advantages: Large capacity, low cost, power failure does not disappear. 、
Disadvantage: Slow reading speed.
Operating system: Provisioning, operation of each hardware.
Windows,linux,cenos,mac,。。。
2. Python First Knowledge
Python history to influence.
Python: Beautiful, clear and simple.
1 Major differences:
PYTHON2X: Source code is not standardized, source confusion, more repeated codes.
Python3x: Re-source code, code specification, beautiful, clear, simple.
Classification of 4,python.
Compiled type:
Compile the code all at once into a two-tier system and run it.
Advantages: High execution efficiency.
Disadvantage: Development efficiency is slow, can not cross the platform.
Representative language: C.
Explanatory type:
The code interprets the lines, interprets the binary, and then runs.
Advantages: The development of high efficiency, third-party libraries, can cross-platform.
Disadvantage: Low execution efficiency.
Representative language: Python.
The type of 5,python.
5.5 Run the first python file:
python space file path, enter.
python2x: The default encoding method is ASCII,
Show Chinese: First line: #-*-Encoding:utf-8-*-.
python3x: The default encoding method is Utf-8.
python2x:print ' content ' Print (' content ')
python3x:print (' content ').
6, variable.
#变量: Store the computed intermediate results for subsequent code use.
variable setting rules:
1, must be a letter, numeric underline any combination.
2, cannot be the beginning of a number.
3, cannot be a keyword in python.
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ',
' def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ',
' finally ', ' for ', ' from ', ' global ', ' if ', ' Import ',
' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ' ,
' raise ', ' return ', ' try ', ' while ', ' with ', ' yield ']
4, the variable cannot be in Chinese.
5, the variable cannot be too long.
6, variables have a descriptive nature.
Ageofoldboy =
numberofstudents =
#下划线
Age_of_oldboy =
number_of_students =
#常量: Constant amount. The default all uppercase variable is a constant.
# ID number, PI,
#注释.
# help you understand other people's code and recall your own code.
#单行注释: # multi-line Comment "" Annotated Content "" "" Annotated Content ""
#基础数据类型:
int number, Integer. Used for calculations. + - * / % //
str; string. In Python, it is the string that is quoted in quotation marks.
#print (' This is a string ')
#print ("This is a string")
#msg = ""
Before the bed was bright moonlight,
Suspicion is ground frost.
‘‘‘
String: Can be added, can be multiplied.
Print (' This is a string ') # print ("This is a string") # # msg = " ' # before the bed was bright moonlight, # suspicion is ground frost. # '# ' # print (msg)
STR + str: concatenation of strings. 、
# msg1 = ' old boy education ' # MSG2 = ' is the best training institution '# #print (MSG1+MSG2)# ' Strong ' # Print (MSG * 8)
Multiply:
STR * INT
msg = ' strong '
#print (MSG * 8)
#bool True False Two states: The Judgment code is true or FALSE.
#print (3 > 2)
#print (3 > 4)
#print (' True ')
#print (True)
# Determine what the data type of this object is ()
# print (' Hello China ') # print (1+2+3+6+7+8+101) # print ((1+2+3+6+7+8+101) *3/5) # Print (((1+2+3+6+7+8+101) *3/5) *4/8) ## A = 1+2+3+6+7+8+101 # B = A*3/5 # C = B*4/8 # print (c)
#print (' True ', type (' true '))
#print (True,type (True))
##变量: Store the computed intermediate results for subsequent code use. #A_ = 4#a*c = 3#___ =#_+ =#_ _ =#12e =##Age1 =#AGE2 = Age1#Age3 = Age2#Age2 =#print (age1,age2,age3) #
10,input user input.
Name = input (' Please enter your name:'= input (' Please enter your age:' ) )print(name,age,type (name), type (age))
11,if.
Other languages:
if (condition) {result}
If condition:
Results
# separate if " " Print (111) If 3 > 2: print (666) print (333)"
# if Else " " name = input (' Please enter your name: ') if name = = ' Rajah ': print (' Old iron, no problem ') Else: print (' ill-treated ... ')
#if elif ... num = int (input (' Please enter ' you have to choose: ')) # str---> int str all consist of numbers if num = = 4: print (' Lunch me please ') elif num = 5:
print (' Dinner me please ') elif num = = 6: print (' Big health, Walk ')'
# if elif ... else " " num = int (input (' Please enter your choice: ')) # str---> int str all consist of numbers if num = = 4: print (' Lunch I please ') elif num = = 5: print (' I'm invited for dinner. elif num = = 6: print (' Big health, Walk ') Else: print (' give you a chance to catch ... ')
# Nesting " " NUM1 = input (' Enter Number ') if num1 = = ' 3 ': num2 = input (' Please enter Number: ') if num2 = = ' 5 ': print (' This can be guessed right ') else : print (' keep trying ')
score = Int (input ("Enter score:"))ifScore > 100: Print("I rub, the highest score only ...")elifScore >= 80: Print("B")elifScore >= 90: Print("A")elifScore >= 60: Print("C")elifScore >= 40: Print("D")Else: Print("It's so stupid ... E")" "
12,while.
#while
To terminate a loop:
" " While condition: result while True: print (' loyalty ') print (' pink Memory ') print (' cool ') print (' windy ') flag = Truewhile flag: Print (' loyalty ') print (' pink Memories ') print (' cool ') flag = Falseflag = Truewhile flag: Print (' Loyalty ') print (' pink Memory ') print (' cool ') flag = False print (' first time ') count = 1flag = Truewhile flag: print (count) count = count + 1 # Count + = 1 if count = = 101: flag = Falsecount = 1while Count < 10 1: print (count) count = count + 1 # count + = 1count = 0while Count < 101: print (count) count = Coun T + 2 count = 0while Count < 101: if count% 2 = = 0: print (count) count = Count + 1while true:
print (111) Print (222) break print (333) print (666) while True: print (111) Print (222) Continue Print (333) print (666)
"
1. Change the conditions.
2,break. (Ends the loop directly.) )
Keywords: break,
Continue, end this cycle and continue the next cycle.
Ps
# Break while Loop calculates the 1+2+3+4...+100 # count = 1 # sum = 0 # While True: # sum = sum + count# count = count + 1# if count = = 101:brea K# # print (sum)
Python Learning D1