Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use python advanced built-in functions

Shulou Source: shulou.com Published: 2022-05-31 10:47:05 09月23日 Update

This article mainly introduces the relevant knowledge of "how to use python advanced built-in functions". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use python advanced built-in functions" can help you solve the problem.

1. Enumerate returns enumerated objects for iterable objects of sequence types.

2. Eval takes out the contents of the string.

Returns the evaluation result of a valid expression in str.

3. Exec runs the compiled string.

4. Filter filter filters out the desired objects.

Example

List1 = [1Personookkkk'] s = enumerate (list1) print (s) # generate an enumerated object for i in s: print (I) # (0,1) # (1SCOKKOG') # (2,3) # (3SCOKKKK') data = list (s) print (data) # [(0,1), (1rect Pokok'), (2,3), (3) 'kkk')] a =' 1+2+3'print (a) # 1+2+3print (eval (a)) # 6b ='we's slots # print (eval (b)) # error report Must be a valid expression c = 12d = 24e = 'sum = c+d'print (e) # sum = c+dexec (e) print (sum) # 36 def func (x): return x > 5List2 = [i for i in range (10)] print (func (6)) # Truef_list = filter (func,list2) print (f_list) # returns a filter object list3 = list (f_list) print (list3) # [6,7,8 9] def func1 (y): if y > 5: return yellow2list4 = [i for i in range (10)] f_list = filter (func1,list4) list5 = list (f_list) print (list5) # [6, 7, 8, 9] # filter only What is filtered is what is returned, and the value def func2 (k): if k is not changed.

Tags: Object yes advanced function content data knowledge generation valid character string type industry expression filter iteration different unmatched practical dictionary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology Microsoft Apple Huawei