Print(All ([1,2,3,4]))#determine if the values in an iterative object are true Print(Any ([0,1,2,3,4]))#determines whether the value inside an object that can be iterated has a true Print(Bin (10))#Decimal Turn binary Print(BOOL ('s'))#convert an object to a Boolean type Print(ByteArray ('ABCDE', encoding='Utf-8'))#Turn the string into a modifiable bytes Print(Callable ('AA'))#determines whether an incoming object can be called Print(Chr (10))#print the ASCII corresponding to the number Print(Ord ('b'))#Print the ASCII code corresponding to the string Print(Dict (a=1,b=2))#Convert Dictionary Print(dir (1))#to print a callable method of an incoming object Print(Eval ('[]'))#Execute Python code, only perform simple, define data types and operations Print(exec('def A ():p'))#Execute Python code Print(Filter (LambdaX:X>5,[12,3,12,2,1,2,35]))#Filter The following iteration objects according to the previous method Print(Map (Lambdax:x>5,[1,2,3,4,5,6])) Print(Frozenset ({1,2,3,3}))#define a non-modifiable collection Print(Globals ())#returns all variables within the program, returning a dictionary Print(Locals ())#return local Variables Print(Hash ('AAA'))#hash A string into a number Print(Hex (111))#The number turns into 16 binary Print(Max (111,12))#Take maximum value Print(Oct (111))#convert numbers to 8 binary Print(Round (11.11,2))#take a few decimals Print(Sorted ([2,31,34,6,1,23,4]))#SortDic={1:2,3:4,5:6,7:8} Print(Sorted (Dic.items ()))#sort by key in the dictionary Print(Sorted (Dic.items (), key=LambdaX:X[1]))#sort by the value of the dictionary __import__('Decorator')#Import a module
Second, filter and map
#filterdef func (a): if a%2==0: return a else: return falsenums=[x for X in range (one)]res=filter (func, Nums) Print (res) #filter: Loop call function, filter save only returns True (non-null-true, nonzero-true)
#map # all_res = []# for num in nums:# res = func (num) # all_res.append (res) # res = map (func,nums) # # # print (res) #循环调 Use the function, and then put the result of each function processing into a list and return
Third, anonymous function
s = Lambda x,y:x+y# The x, y in front of the colon number is the entry parameter, and after the colon is the return value print (S (1,9)) #因为函数即变量, if a variable is not set to save the lambda, it is not in memory, cannot be executed, All put it in the variable s
Iv. JSON processing
Import JSON dic = {"name": "Niuniu", "age": + Print (Json.dumps (DIC)) #把字典转成json串 fj = open (' A.json ', ' W ') Print (Json.dump (DIC,FJ)) #把字典转换成的json串写到一个文件里面 S_json = ' {' name ': ' Niuniu ', ' age ': ', ' ' status ': true} ' Print (Json.loads (S_json)) #把json串转换成字典 fr = open (' B.json ', ' R ') print (Json.load (FR)) #从文件中读取json数据, then turn into a dictionary
Python Learning Note 4-built-in functions, anonymous functions, JSON processing