A built-in function operation 2 ! # Usr / bin / the env Python . 3 # - * - Coding: UTF-. 8 - * - . 4 # 1.locals () and Globals () . 5 # DEF FUNC (): . 6 # X = 1 . 7 Y = 2 # . 8 # Print (about locals ()) . 9 # Print (Globals ()) 10 # FUNC () . 11 12 is # 2.eval, Exec, and the compile 13 is # Print (123) 14 # " Print (456) " string # 15 # the eval ( " Print (456) ") # python string into bar code to execute (return value) 16 # Exec ( " Print (7889) ") # python string into bar code to execute (no return value) . 17 # NUM = the eval ( '+. 4. 5. 6 +') # executed, the return value 18 is # Print (NUM) . 19 # 20 is # NUM = Exec ( '. 4 +. 5 +. 6') # executed, no return value 21 is # Print (NUM) 22 is # the compile # do compiler 23 is # COM = the compile ( '. 1 + 2 +. 3 ',' ', mode =' eval ') # save time 24 # Print (the eval (COM)) 25 # Print (the eval (' +. 1 + 2. 3 ')) the above effects and # phrase compile () the same effect 26 is 27 28 # 3. Print 29 # Print ( '123',End = '') does not wrap # 30 # Print ( '456', End = '') 31 is 32 # Print (l, 2,3) 33 is # Print (1,2,3,4,5,6, On Sep = ',') 34 is 35 36 37 [ # Print small sample () function 38 is # Import Time 39 # Import SYS 40 # for I in Range (0,101,2): 41 is # Time .sleep (0.1) 42 is # char_num = I / / 2 # print the number # 43 # per_str = '%s%% : %s\n' % (i, '*' * char_num) if i == 100 else '\r%s%% : %s'%(i,'*'*char_num) 44 # print(per_str,end='', file=sys.stdout, flush=True) 45 46 # import sys 47 # for i in range(0, 101, 2): 48 # time.sleep(0.1) 49 # char_num = i // 2 50 # per_str = '\r%s%% : %s' % (i, '*' * char_num) 51 # print(per_str, file=sys.stdout, The flush = True) 52 is 53 is # 4.input () 54 is # 5.type () 55 # 6.hash 56 is # Print (the hash ( 'asdsffd')) # several start again, and then is constant run once changed 57 is # Print (the hash ( 'asdsffd')) 58 # Print (the hash ( 'asdsffd')) 59 # Print (the hash ( 'asdsffd')) 60 # Print (the hash ( 'asdsffd')) 61 is # Print (the hash ((1,2,3,4))) 62 is 63 is # 7. The Open 64 # R & lt, W, A, R & lt +, W +, A + (plus can B) 65 # F = Open( 'tmp', 'r + ') # r + open file 66 # Print (F. Read (. 3)) # If read write, adding 67 # f.seek (. 5) # If seek specifying the location of the cursor, to from this starting position covering this writing 68 # F. write ( 'AAAAAA') # if the direct write, the head cover 69 # F. Close () 70 71 is 72 #. 8 .__ Import __ () 73 is # Import OS 74 # Import SYS 75 # Import Time 76 77 # 9.callable: View can call 78 # Print (Callable (123)) can not call numbers # result is False 79 # Print(a Callable ( Open )) # can call the function returns True 80 81 # 10.dir view the data type of the method 82 # Print (dir (__ builtins __)) # error ,, but in fact looked at not being given 83 # Print (dir (int )) 84 # Print (the dir (List)) 85 # Print (the dir (0)) and int as # 86 # Print (SET (the dir (List)) - SET (the dir (tuple))) 87 # 11. The 88 # int = num1 (123) 89 # num2 = int (12.3) cast to type int # 90 # Print (num1, num2) 91 is # 12. The take quotient / remainder 92 #Print (divmod (7,3)) 93 # calculates a minimum value 13. 94 # Print (min (1,2,3,4)) 95 # Print (min ([5,6])) 96 # 13. Calculation Maximum value 97 # Print (max (1,2,3,4)) 98 # Print (max ([5,6])) 99 100 # 14.sum summation 101 # Print (SUM (1,2,3,4 )) # mistake, sequence parameters, not the hash 102 # Print (SUM ([5,6])) 103 # Print (SUM ((1,2,3,4))) 104 105 two or less # It is the same way 106 # Print(. 1 + 2) 107 # Print (int (. 1). __Add__ (2)) 108 109 # 15.round accuracy 110 # Print (round (3.1415926,2)) two reserved # 111 112 113 # 16.pow ( ) exponentiation 114 # Print (POW (2,3)) 115 # Print (2 **. 3) 1 16 117 1 18 # and 17. a data structure of the 119 # 1.reversed () reversing the order of 120 # L = [ 1,2,3,4] 121 # Print (list (reversed (L))) # is generated a new list, no change in the original list (reversed would not be able to not reversed, with Reverse) 122 # 123# # L.reverse () # changed, on the basis of a list of current changes on the original list 124 # Print (L) 125 126 # 2.slice sections 127 # 3.format () except formatted # job 128 # Print (the format ( 'Test', '<20 is')) 129 # Print (the format ( 'Test', '> 40')) 130. # Print (the format ( 'Test', '^ 40')) 131 is 132 # 4.bytes 133 S = 'Hello' 134 # bytes SB = (S, encoding = 'UTF-. 8') 135 # Print (SB) 136 # Print (SB. decode ( 'UTF-. 8' )) 137 138ByteArray SB2 = # (S, encoding = 'UTF-. 8') 139 # SB2 [0] = # 229 to know enough to modify 140 # Print (SB2. Decode ( 'UTF-. 8')) 141 is # Print (SB2) 142 # Print (SB2 [0]) 143 144 # 5. The the repr 145 # Print ( the repr ( '1234')) 146 # Print ( the repr (1234)) 147 # Print ( ' name : R & lt%'% ( 'Egon') ) # how you would pass in what format printed out by 148 149 # 6.set and frozenset (can not change the set) as list and tuple 150 151 # 7.enumerate 152 # l=['a','b'] 153 # for i in enumerate(l): 154 # print(i) 155 # 156 # for i ,j in enumerate(l): 157 # print(i,j) 158 159 # 8.all和any 160 # print(all([1,2,3])) 161 # print(all([0,2,3]))#因为0是False 162 # 163 # print(any([1,2,3])) 164 # print(any([0,2,3])) 165 166 # 9.zip() 167 # l=[1,2,3] 168 # l2=[4,5,6,7,8] 169 # print(zip(l,l2)) 170 # print(list(zip(l,l2))) 171 # l3={'k':'v'} 172 # print(list(zip(l,l3))) 173 174 # 10.sort和sorted 175 # l=[1,3,5,-2,-6] 176 # l.sort() 177 # print(l) 178 # l2=[1,3,5,-2,-6] 179 # print(sorted(l2)) 180 # print(sorted(l2,key=abs)) 181 # Print (sorted (L2, Key = ABS , Reverse = True)) # default from small to large, to modify True, the descending order 182 183 184 # 11.map (): I want them to my list of each value do inside the function operation 185 # L = [1,2,3,4,5] 186 # DEF pow2 (X): 187 # return X X * 188 # Print (List (Map (pow2, L) )) 189 190 191 # 12.filter (): found from among a list of all matching the filter, consisting in a new listing 192 # DEF AAA (X): 193 # return X. 1% 2 == 194 # RET = list (filter (aaa, [1,2,54,3,6,8,17,9])) 195 # Print(right)
Classification: Python-related