python built-in functions use

print (abs(1))    #Absolute value, positive numbers are themselves 
print (abs(-1))   # 1

print (all([1,2,3, " 1 " , '' ]))   # Calculate whether the iterable object is true, if one of them is false, it will be displayed as false 
print (all( '' ))   # If the iterable is empty, return True.

print (any([1,2,3, " 1 " , '' ])) # Calculate whether the iterable object is true, if one of them is true, it will be displayed as true

print (bin(3))   #Convert decimal to binary 
print (hex(3))   #Convert decimal to hexadecimal 
print (oct(12)) #Convert   decimal to octal

print (bytes( " test " ,encoding= " utf-8 " )) # Convert the string to binary

print (chr(97)) #Print   the ascii code data corresponding to 97

print (dir(all))   #Print the methods and properties of the all object


# eval("Data to be extracted") #The string data can be extracted, and the operations in the string can also be calculated

print (isinstance(1,int)) #Determine   whether a data is the corresponding data type

print (globals()) #Print   the current global variable 
print ( __file__ )    #Print the path of the current file relative to the path

print (locals()) # print the current local variables

print(list(zip((1,2,3,4,5),("a","b","c"))))   #[(1, 'a'), (2, 'b'), (3, 'c')]
print(list(zip(['a','b'],'1234')))   #[('a', '1'), ('b', '2')]
print(list(zip("hello",'12345')))   #[('h', '1'), ('e','2'), ('l', '3'), ('l', '4'), ('o', '5')]



print (max(5,10))    # 10 #Data between different types cannot be compared 

li = [(1, ' b ' ),(2, ' a ' ),(3, ' d ' )]
 print ( max(li))    # (3, 'd') 

li = [(1, ' b ' ),(1, ' a ' ),(1, ' d ' )]   #Compare the first 1 in turn to find All the same, this is just comparing the second string bad 
print (max(li)) # (1, 'd') 
print (max( " a10 " ,"c10","d10"))   #d10

print(pow(2,3))  #2**3
print(pow(2,3,2))   #2**3%2


ret = [
    {'name':'d',"age":221},
    {'name':'c',"age":332},
    {'name':'a',"age":89},
    {'name':'b',"age":111},
]
print (max(ret,key= lambda dic:dic[ ' age ' ]))   # {'name': 'c', 'age': 332} 
# above max(ret,key=lambda dic:dic['age ']) is equivalent to the following for loop, assigning ret to lamba in turn for processing, and then max calculation size 
v = []
 for i in ret:
    v.append(i['age'])
print(v)        #[221, 332, 89, 111]



print(list(reversed([5,3,8,1])))   #[1, 8, 3, 5]

print (round(3.5))    # 4 4 round 5 

l = " apple " 
s1 = slice(3,5)   # same as slice[3:5] 
print (l[s1])    # le

print(sorted(["c","a","b"]))   #['a', 'b', 'c']  排序

name_dic = {'a':22,'b':33,'c':11}
print(sorted(name_dic))             #['a', 'b', 'c']
print(sorted(name_dic,key=lambda key:name_dic[key])) #['c', 'a', 'b']
print(sorted(zip(name_dic.keys(),name_dic.values())))  #[('a', 22), ('b', 33), ('c', 11)]


print (sum(range(5)))   # 10, calculation and 
print (sum([1,3,4,5,6]))    # 19

# import 'test' error 
__import__ ( " test " )    # Join is a string type; you need to import this module, you need to use __import__

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325006999&siteId=291194637