1. Absolute value
>>> a = -1>>> print (ABS (a)) 1
2.all: True when incoming elements are true
>>> all ([true>>>]) bool (None) false>>> bool ("") false>>> bool ("") true> >> bool ([]) false>>> bool (()) false>>> bool ({}) false>>> bool (0) False
3.any: As long as one is true, it is true.
>>> any (["", [],{},none]) false>>> any (["", [],{},none,1]) True
4.ascii: __repr__ This method of performing objects
>>> class Foo: ... def __repr__ (self): ... return ' aaaa ' ... >>> f = Foo () >>> ret = AS CII (f) >>> print (ret) AAAA class:>>> a = -1>>> a.__abs__ () 1>>> a = -1>>> abs (a) 1
5.bin: Binary Conversion
>>> Bin (5) ' 0b101 '
6.bool
7.callable: Whether it can be called
>>> f = lambda x:x+1>>> f (5) 6>>> callable (f) True
Conversion between 8.ascii yards and numbers
>>> Ord (' a ') 97>>> ord (' a ') 65>>> >>> chr (+) ' C '
9.dict: Create a dictionary
10.dir
11.divmod
>>> Divmod (5,4) (1, 1) >>> divmod (1, 0) >>> Divmod (6,4) (1, 2) >>>
12.enumerate
>>> L1 = [' A ', ' B ', ' C ']>>> for I,item in Enumerate (l1,1): ... print (I,item) ... 1 A2 B3 C
13.eval
>>> s = "6*8" >>> type (s) <class ' str ' >>>> eval (s) 48
14.map
>>> L1 = [1,2,3]>>> def sum (x): ... return x + 10 ... >>> new_list = map (sum,l1) >>> L2 = List (new_list) >>> print (L2) [11, 12, 13]
15.filter
>>> L1 = [10,20,30]>>> def fl (x): ... if x > All: ... else:--RE Turn False ... >>> new_list = filter (FL,L1) >>> print (list (new_list)) [20, 30]
16.float
>>> a = 1>>> type (a) <class ' int ' >>>> b=float (a) >>> type (a) <class ' int ' >>>> type (b) <class ' float ' >>>> b1.0
17.format
>>> name = "Test {0} {1}" >>> result = Name.format (' test1 ', ' test2 ') >>> print (result) test test1 Test2 >>> name = "Test {name} {id}" >>> result = Name.format (name= ' test1 ', id= ' test2 ') >>> print (result) test test1 Test2
18.globals: All currently available variables
>>> Globals () {' __builtins__ ': <module ' builtins ' (built-in), ' L1 ': [ten, +], ' L2 ': [One, one, ten], ' Foo ' : <class ' __main__. Foo ';, ' __spec__ ': None, ' FL ': <function fl at 0x1021dbbf8>, ' __doc__ ': None, ' new_list ': <filter object at 0x 1021e5e10>, ' sum ': <function sum at 0x1021dbae8>, ' __package__ ': None, ' I ': 3, ' a ': 1, ' __name__ ': ' __main__ ', ' B ': 1.0, ' ret ': ' AAAA ', ' Item ': ' C ', ' s ': ' 6*8 ', ' F ': <function <lambda> at 0x1021db9d8>, ' __loader__ ': <CLA SS ' _frozen_importlib. Builtinimporter ' >}>>>
19.hex:16 binary Conversion
>>> Hex ' 0x3c '
20.max
>>> Max (11,22,33) 33
21.min
>>> min (11,22,33) 11
22.OCT: Octal
>>> Oct (Ten) ' 0o12 '
23.reversed
>>> L1 = [10,20,30]>>> list (reversed (L1)) [+, 10]>>>
24. Rounding
>>> round (8.4) 8>>> round (8.6) 9
25.vars: Key and values are returned
>>> VARs () {' __builtins__ ': <module ' builtins ' (built-in), ' L1 ': [ten, +], ' L2 ': [One, one, ten], ' Foo ': & Lt;class ' __main__. Foo ';, ' __spec__ ': None, ' FL ': <function fl at 0x1021dbbf8>, ' __doc__ ': None, ' new_list ': <filter object at 0x 1021e5e10>, ' sum ': <function sum at 0x1021dbae8>, ' __package__ ': None, ' I ': 3, ' a ': 1, ' __name__ ': ' __main__ ', ' B ': 1.0, ' ret ': ' AAAA ', ' Item ': ' C ', ' s ': ' 6*8 ', ' F ': <function <lambda> at 0x1021db9d8>, ' __loader__ ': <CLA SS ' _frozen_importlib. Builtinimporter ';
26.zip
>>> x = [1,2,3]>>> y = [4,5,6]>>> zipped = Zip (x, y) >>> list (zipped) [(1, 4), (2, 5), (3 , 6)]
27.pow: Power
>>> Pow (2,3) 8
28.sorted: Sort
>>> ([sorted]) [1, 2, 3]>>> sorted ([3,1,2]) [1, 2, 3]>>> sorted ([' B ', ' C ', ' a ']) [' A ', ' B ', ' C ']
This article is from the "guoxianqi2016" blog, make sure to keep this source http://guoxianqi2016.blog.51cto.com/11407620/1766436
Python built-in functions