# ! / Usr / bin / to python3 # Python basic syntax and data types # to python3 a plurality of statements in a row, separated by a semicolon (;) Print ( " AAA " ); Print ( " BBB " ) # Basic data types, the type of long removed Print (type (. 1 )) Print (type (1.0 )) Print (type ( " STR " )) # Allows multiple variables continuous assignments a=b=c=1 print(a,b,c) a,b,c=1,2,"bb" print(a,b,c) # Standard data types 6 kinds # Number The (digital) # String (String) # List (list) # Tuple (tuple) # Sets (set) # of Dict (dictionary) # Number The (digital) # support int float bool complex (complex) # numerical Print ( " . 5 + =. 3 " ,. 5 +. 3 ) Print ( " 5-3 = " , 5-3 ) Print ( " . 5 *. 3 = " ,. 5 * 3 ) Print ( " divide down float 2 / =. 4 " , 2 /. 4 ) Print ( " divide down. 4 = integer // 2 " , // 2. 4 ) Print ( " modulo 3 = 10% " , 10%. 3 ) Print ( "Power ** 2 = 4 " , 4 ** 2 ) Print ( " prescribing 0.5 ** = 4 " , 4 * 0.5 ) # String (String) # elements are immutable String = " ABCDEFG " Print (String) Print (String [0]) Print (String [0: -1]) # start to finish Print (String [2:]) # from the lower end of the subscript 2 Print (String [2:. 4]) # from the subscript 2. 1-n-[m, n-) Print (String * 2) # output 2 # List (list) # variable element listDemo = [ " AA " ,. 1, " BB " , 2 ] Print (listDemo) Print (listDemo [0]) # output index 0 Print (listDemo [2:]) # starting from index 2 to the tail Print (listDemo [. 1:. 3]) # at index 2 to the n--. 1 [m, n-) Print (listDemo * 2) # output 2 listDemo [0] = " alternative " Print (listDemo) # amended # Tuple (a tuple) # elements immutable tupleDemo = ( " AA " ,. 1, " BB " , 2 ) Print (tupleDemo) Print (tupleDemo [0]) # output index 0 Print (tupleDemo [2:]) # 2 start index from the tail Print (tupleDemo [. 1:. 3]) # at index 2 to the n--. 1 [m, n-) Print (tupleDemo * 2) # output 2 tupleDemo = () # empty tuple tupleDemo = (a,) # an element Print (tupleDemo) # The Set (set) # a non-repeating random sequences setDemo = { " A " , " B " , " C " } Print ( " set A " , setDemo) # set may be set intersection and difference set setDemo2 = { " a " , " B " } Print ( " set B " , setDemo2) Print ( " AB of the difference set " , setDemo- setDemo2) Print ( "AB union ", setDemo | setDemo2) Print ( " AB intersection " , setDemo & setDemo2) Print ( " AB does not exist at the same time " , setDemo ^ setDemo2) #字典 dictDemo={"tom":"90","jerry":"75"} print(dictDemo) print(dictDemo["tom"]) print("keys:",dictDemo.keys()) print("values",dictDemo.values()) #移除 key 返回value print("移除tom ",dictDemo.pop("tom")) print(dictDemo) # Python common data conversion '' ' int(x) str(x) tuple (s) converted into a sequence of tuples list (s) to convert the sequence listing ''' # Python Notes Print ( " single-line comments # " ) Print ( " multi-line comment single quotation mark (3 ') " ) Print ( " multi-line comment double quotation marks (three double quote) " )
Six basic data types
Guess you like
Origin www.cnblogs.com/libragyf/p/12066008.html
Ranking