Python Basics (i): Operators: Arithmetic operations:
In addition to the basic +-*/, you need to know://To take the integer portion of the returned market quotient for example: 9//2---> 4, 9.0//2.0--->4.0
% is the remainder of the division returned by the remainder is 0 for example: 3 3---> 0, Surplus: 6 3--->2
Logical operators:
And, or, not
Comparison operators:
= = Determines whether two numbers are equal,! = Determines whether two numbers are unequal, >, <, >=, <=
Member operators:
List_1 =[1,2,3,4,5]
In:
1 in list_1---> True
Not in:
6 in list_1---> False
Format character. Format (): Control accuracy:
PI = 3.1415926
Print ("PI is accurate to 3 digits after decimal point: {0:.3f}". Format (PI))
Pi is accurate to 3 digits after the decimal point: 3.142
Padding characters:
W_1 = "word"
"{0:-^30}". Format (w_1)---> '-------------word-------------'
If judgment and while for loop:
While loops generally determine the condition of a loop by whether the value is satisfied
A For loop is typically a pair of variables that can hold multiple data and traverse
List_2 = [1,2,3,4,5,66] for in list_2: print(i)
Multiplication table ()
i = 0 while I <=9: = 1 while m <= i: print( '%d*%d=%d'% (m,i,m*i), end=') +=1 Print(") i+=1
Scissors
1 ImportRandom2 3Player = input ('Please enter: Scissors (0) stone (1) cloth (2):')4 5Player =Int (player)6 7Computer = Random.randint (0,2)8 9 if(player = = 0) and(Computer = = 2))or((Player ==1) and(computer = = 0))or(player = = 2) and(Computer = = 1)):Ten Print('win, Haha, you're so awesome.') One elifPlayer = =Computer: A Print('a draw, or another inning.') - Else: - Print('lose, do not go, wash your hands and then come, the battle till Dawn')Break and Continue
The function of break: To end the entire cycle
Continue: Used to end the cycle, followed by the next cycle
First knowledge of Python