Import Math DEF A (A, B): Print ( " value of the first parameter " + STR (A)) Print ( " value of the first parameter " + STR (B)) A =. 1 B = 2 a (B, a) # value of the first parameter 2 # value of a second parameter # formatting characters # % F mean floating point format characters,%. 1f formatting means floating-point characters, and retain a decimal (rounded) a1 = 2.3333 a2 = 4.4567 Print ( ' value is a reserved a1:. 1F% ' % a1) Print ( ' value a2 are three retention:% .3f '% A2) # Math Math module Import # Math.ceil () to get out of the values rounded up Print (Math.ceil (A1)) # . 3 # return # time with return, or the print receiving variable, a return value obtained def B (): B1 =. 1 B2 = 2 return B1, B2 Print (B ()) Print (type (B ())) # (1,2) # <class 'tuple'> # tuple tuple # tuples and Similarly list, except that the elements of the tuple can not be modified. Use tuple () list uses [] # Create tuples TUP1 = (1,2,3,4,5 ) # No braces may tup2 = 1,2,3,4,5 tup3= "a","b","c" print(tup1) print(type(tup1)) print(tup2) print(type(tup2)) print(tup3) print(type(tup3)) #(1, 2, 3, 4, 5) #<class 'tuple'> #(1, 2, 3, 4, 5) #<class 'tuple'> #('a', 'b', 'c') #<class 'tuple'> "TUP1 [0]:"(Printaccess tuples similar list#() tup4 =Create an empty Ganso# , TUP1 [0]) Print ( " tup2 [. 1:. 5]: " , tup2 [. 1:. 5 ]) # TUP1 [0]:. 1 # tup2 [. 1:. 5]: (2,. 3,. 4,. 5) # While the element value tuple can not be modified, but may be connected tuples tup5 = tup2 + tup3 Print (tup5) # (. 1, 2,. 3,. 4,. 5, 'a', 'B', 'C') # Similarly, although not remove elements, but can be deleted entirely del tup5 Print ( " after deletion tuple: " ) # Print (tup5) # NameError: name 'tup5' iS not defined # basic tuple operators and built- function Print (len (TUP1)) Print (tup3 * 3 ) #5 #('a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c') #迭代 for i in tup2: print(i) #1 2 3 4 5 print(max(tup3)) print(min(tup2)) print(tuple([1,2,3])) #c #1 #(1, 2, 3)
Or pictures convenient