Today's Contents: - three characteristics of the variable type: viewing data type id: represents the variable address in memory, is a string of numbers value: the value of variables - process control control process, control the occurrence of certain events - if branch is determined: parts: # condition when established perform Print ( 'condition is satisfied!') # If the if condition is not satisfied, here is performed elif Analyzing conditions: Print ( "another condition is satisfied ') # If the if condition is not satisfied, the execution here elif Analyzing conditions: Print ( "another condition is satisfied ') # If the condition is not satisfied if and elif, here is executed else: # If the condition is not satisfied then execute Print ( 'condition is not satisfied!')
Code
Import Time List1 = [ ' 18-year-old tank, is true. ' ] # Print (type (List1)) # ID Print (ID (List1)) # 4,648,825,800 # 4,620,567,608 the time.sleep ( . 5 ) Print ( " program end, list1 destroyed ' ) # variable and non-variable # rewriting the data when, id called constant variable type, otherwise called hard type. (Dictation) # Variable List = [ ' Tank, Jason ' ] Print ( ' List1 before modification ID: ' , ID (List1)) list1.append ( 'Feng Xu ' ) # [' Tank, 'Jason'] the append. (Feng Xu) Print ( ' after list1 modified ID: ' , ID (list1)) # immutable: tuple tuple1 = (l, 2,3 ) Print (ID (tuple1)) Print (type (tuple1)) tuple1 = (2,3,4 ) Print (ID (tuple1)) '' ' the user interacts with the program: iNPUT () input print () output ' '' username = iNPUT ( ' enter username: ' ) Print (username) password = iNPUT ( ' Please enter your password ' ) Print(password) # if: # username == 'tank'ture # and: the left and right conditions are only for the Ture Ture, otherwise to false # password ==' 123 'Ture # determines if condition: If the condition is determined == Ture , under the code execution IF IF username == ' Tank ' and password == ' 123 ' : # false and false ture --- >> Print ( ' Login successful ' ) the else : Print ( ' Login failed ' ) # placeholder Fu:% S str1 = ' handsome ' Print( ' Tank S% ' % (str1,)) # Tank handsome str2 = '' Print ( ' confidence to develop mind. 1: S% ' % (str2,)) price1 = INPUT ( ' Enter the user deductions month monthly: ' ) All = the iNPUT ( ' Please enter the user's current balance: ' ) Print ( ' Dear mobile users, your monthly rent for the month [% s] yuan, account balance [% s] dollars! ' % (price1 , All)) # - arithmetic operators) Print (+. 1. 1) # ( N1. 1 = # N1 = N1 + N1 +. 1 # # Print (N1) # 2 +. 1 = N1 # assignment operator: - = Print (10-1) # . 9 # * = Print (* 12 is 12 is) # 144 Print (11/3) # 3.666 .... Print (11/3) # . 3 Print (. 11%. 3) # 2 # comparison operators Print (== 2. 1) # False Print (. 1> 2) # FASLE Print (. 1 <2) # True Print (. 1> = 2) # FASLE Print (. 1 < 2 =) # True # iS: the above mentioned id compares two variables are equal 10 = X Print (ID (X) == ID (X)) # True Print (X IS X) # True # logical operators # and: the left and right conditions are True it is True, otherwise to false Print (X 1 == and the X-== 10) # False Print (== the X-10 and the X-== 10) # True # or: to determine whether the two sides set up, it was established 1 True Print (== the X-10 or the X-== . 1) # ture # Not: Invert Print (X == 10) # ture Print ( Not X == 10) # to false # NO -> and -> or # to true or to false Print ( Not X ==. 1 or X == 10 and X 20 is ==) # True # chain assignment n-10 = Y = n- Z = n- Print ( n-, y, Z) n- = Z = y = 10 Print (n-, y, Z) # intersecting assignment X = 10 y = 20 is # X and the value of y is interchanged # X = 10 y = 20 is Z = y # 10 Y = X- # 20 is Y = Z # 10 X = 10 The Y = 20 is # 10,20 = Y = 10, X = 20 is X, Y = Y, X Print (X, Y) # 20,10 # decompression assigned # 0. 1 2 List1 = [l, 2,3 ] X = List1 [0] Y = List1 [. 1 ] Z = List1 [2 ] Print (X, Y, Z) # . 1 2. 3 X, Y, Z = List1 Print (X, Y, Z) # . 1 2. 3 '' ' iF branch ' '' # guess character game: guess whether the character entered by the user is 9527. Number the = 9527 gUESS = the iNPUT ( ' Please enter the digital guess ' ) Print (GUESS) Print (of the type (GUESS)) # str # string into an integer type GUESS = int (GUESS) Print (of the type (GUESS)) # int IF GUESS == Number The: Print ( ' guessed it! ' ) elif gUESS < Number the Print ( ' guess small ' ) the else : Print ( ' I guess big! ' )