Built-in functions
"Py3.5 Official Document" Https://docs.python.org/3.5/library/functions.html#abs
|
Built-in Functions |
|
|
ABS () |
Dict () |
Help () |
Min () |
SetAttr () |
All () |
Dir () |
Hex () |
Next () |
Slice () |
Any () |
Divmod () |
ID () |
Object () |
Sorted () |
ASCII () |
Enumerate () |
Input () |
Oct () |
Staticmethod () |
Bin () |
Eval () |
Int () |
Open () |
STR () |
BOOL () |
EXEC () |
Isinstance () |
Ord () |
SUM () |
ByteArray () |
Filter () |
Issubclass () |
POW () |
Super () |
Bytes () |
Float () |
ITER () |
Print () |
Tuple () |
Callable () |
Format () |
Len () |
Property () |
Type () |
Chr () |
Frozenset () |
List () |
Range () |
VARs () |
Classmethod () |
GetAttr () |
Locals () |
Repr () |
Zip () |
Compile () |
Globals () |
Map () |
Reversed () |
__import__ () |
Complex () |
Hasattr () |
Max () |
Round () |
|
Delattr () |
Hash () |
Memoryview () |
Set () |
|
Important functions
filter (function, sequence): executes function (item) on item in sequence and returns an iterator that executes a result of true to a filter object. Can be seen as a filter function. "Do not change the original value, only one filter effect"
def fun1 (s): if s! = ' A ': return Sret = Filter (fun1, str) print (ret) # RET is an iterator object <filter objects at 0x00000 00000a4c518>print (List (ret)) # [' B ', ' C ', ' d ']
Eval: Calculator function "Use within quotation marks" and return the original type of data directly
Print (eval (' 1+2+3+4+5+6+7+8+9+10 ')) # 55
map (function, sequence) : Executes function (item) on item in sequence, and executes the result into a map iterator returning "change element value"
str = [' m ', ' g ', ' f ', ' W ']def fun2 (s): return s + "Ood" ret = map (fun2, str) print (ret) # Map Object iterator print (list (r ET) # [' Mood ', ' good ', ' food ', ' wood ']
Note: map also supports multiple sequence, which requires that the function also supports the corresponding number of parameter inputs:
def add (x, y): return X+yprint (list (map (add, Range), range (10))) ##[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
the difference between map and filter:
def f (s): return s + ' ood ' li = [' f ', ' m ', ' g ', ' H ']print (list (map (f, Li))) # [' Food ', ' mood ', ' good ', ' hood '], pieced back heavy New Output print (List (filter (F, Li)) # [' F ', ' m ', ' g ', ' h '], output the original value
reduce (function, sequence, starting_value): invokes function for the item order in sequence, and can be called as an initial value if there is a starting_value. "Direct return results, the difference between map and filter, factorial is very convenient"
From Functools import reducedef FAC (x, y): return x * yprint (Reduce (FAC, range (1, 5)) # 24print (Reduce (FAC, range (1, 5),) # 240getattr (obj, name, default) function: Remove a property or method from the Obj object without printing the default value class Foo: def __init__ (self, name, Age): self.name = name self.age = Ageobj = Foo (' FTL ', +) print (obj.name) b = ' name ' Print (' obj.__dict__[b]: ', obj. __DICT__[B] # through the Dictionary value print ("GetAttr (obj, ' name '):", GetAttr (obj, ' name ')) # takes the value setattr (obj, ') through the built-in function getattr School ', ' Xupt ') print (hasattr (obj, ' School ')) print (Delattr (obj, ' School ')) # Other built-in methods that manipulate the members of an object in the form of a string
Learning---python learning with built-in functions