Built-in functions
abs absolute value of the print (abs (-1)) === "1
all all Boolean values are True is True, If the iterable is empty, return True.
print(all([1,2,-1,""]))===》False,print(all([0,""]))===》False
any either True Boolean value of True was
bytearray
bytes string into a byte
# Define a variable, save the Unicode strings to the memory, on the hard drive of their choice, encoding the final result is a binary # Chinese utf-8 corresponding to 3 bytes # coding name = " hello " Print (bytes (name, encoding = " UTF-8 " )) # ### b '\ XE4 \ XBD \ XA0 \ xe5 \ xa5 \ XBD' # decode what encoding on what decoding, decoding is default-8 UTF # ASCII can not be edited Chinese Print ( bytes (name, encoding = " UTF-. 8 " ) .decode ( " UTF-. 8 " )) # ### hello
CHR Print (CHR (97)) A ####
All what method the print object, print name , Print (the dir (All)) ####
divmod
# Quotient and remainder, eg: Paging, one has three records, a remaining one in a separate
print (divmod (10,3)) #### (3, 1)
eval
#eval () results in the string data extracted
Express = ". 1 + 2 * (. 3 / 3-1) -2"
Print (the eval (Express)) ### - 1.0
hash may hash the data type that is immutable data type, the data type can not change the hash type
hash is an algorithm, a hash value obtained, regardless of the length of a hash value string length number, obtained is fixed;.. 2 can not be obtained in accordance with Ha Xi reverse thrust value; 3 variables constant, hash values of the same
determination process software has been tampered with. Downloading a piece of software, the software along with the hash value to the other side, the software is downloaded to the local hash check with hash algorithm, if the hash values are the same, it means that has not been modified, secure
print (hash ( "32444333333333333344444") ) #### - 2091919439
Help Print (Help (All)) # print specific methods
bin、hex、oct
print (bin (10)) # 10 hex -> binary 0b1010 ###
Print (hex (10)) hex # 10 -> 16 hexadecimal 0xA ###
Print (OCT (10)) into # 10 system -> octal ### 0o12
the isinstance Print (the isinstance (. 1, int)) ## True, this type is not determined
Globals , print global variables
= name " Recently invoice " Print (Globals ()) # ### print global variable # { 'the __name__': '__main__', 'the __doc__': None, '__PACKAGE__': None, '__loader__': < _frozen_importlib_external.SourceFileLoader object at 0x0074D250>, '__spec__ ': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>,' __file__ ':' C: / Users / pujialou / PycharmProjects /python_day10_1/day1-/16.py ',' __cached__ ': None ,' name ':' Recently invoice '} name = " Recently invoice " DEF Test (): name = " color value high " # Print (Globals ()) Print (about locals ()) the Test () # result #{ 'Name': 'color value of the high'}
zip fastener method, transmission sequence value (list, tuple, string)
# Positions from front to back, if there is no corresponding value is not output
print (list (zip (( " a", "b", "c"), (1,2,3)))) #### [( ' a ', 1), (' b ', 2), (' c ', 3)]
p={"name":"alex","age":18,"gender":"none"} print(list(zip(p.keys(),p.values()))) ####[('name', 'alex'), ('age', 18), ('gender', 'none')]
print(list(zip(["a","b"],"124546")))####[('a', '1'), ('b', '2')]
max and min
1 can be used as long as the iteration; 2. Each element is compared from left to right; print (max ( "a11" , "b3", "c2")), the output is c2;. 3 different types can not be comparison, EG: max ( "A11", "B3", 10) being given
li={"age1":10,"age2":50,"age3":60,"age4":20} print(max(li.values()))####60 print(max(li))####age4
# Value and maximum age value Age Li = { " AGE1 " : 10, " Age2 " : 50, " Age3 " : 60, " age4 " : 20 is } Print (max (ZIP (li.values (), li.keys ()))) # (60, 'Age3')
li=[(5,"a"),(1,"b"),(3,"u"),(4,"d")] print(list(max(li)))####[5, 'a']
sort out:
# 1, using a simple L = [1,2, -100,33] Print (max (L)) 33 is ####
# Dictionary DIC = { "AGE1": 18 is, "Age2": 10} # Comparative Keys Print (max (DIC)) #### Age2 #, comparison values, but do not know which Keys Print (max (dic.values ())) #### 18 # has Keys, values Print (max (ZIP (dic.values (), dic.keys ()))) #### (18, 'AGE1')
#max processing method can pass, people carried out the for loop, each element to remove lambda acquisition process, so that the return value of lambda max is given to compare
#max (people) comparing each represents a dictionary, being given; is to compare the current age value corresponding to each dictionary so taken out, taking age corresponding values
#max (people, the lambda P = Key: people [ "age"])
Print (max (people, the lambda Key = DIC: DIC [ "age" ]))
# corresponds
# RET = []
# for people in Item:
# ret.append (Item [ "Age"])
# results
# { 'name': 'alex ', 'age': 100}
05 python s3 day17 other built-in functions .ev4 not see