Python Learning note 11-python built-in functions
First, look at the Python function description:
https://docs.python.org/2/library/
Second, Python built-in functions
1, ABS get absolute value:
View ABS from the Python website
View ABS with Help
in [+]: Help (ABS)
Help on built-in function abs in module __BUILTIN__:
ABS (...)
#返回一个number ABS (number)
Return the absolute value ofthe argument. #返回绝对值
(END)
ABS Example:
in [+]: def fun (x): ...: If x < 0: Return-x ...: return x ...: in [+]: Fun (Ten) out[1 5]: 10In [+]: Fun ( -10) out[16]: 10In [+]: ABS ( -10) out[17]: 10In []: ABS () out[18]: 10In [+]: ABS ( -100) out[19]: 100
2. Maximum and minimum value of the list
in [+]: Max ([1,2,3,4,5]) out[22]: 5In [max]: Min ([1,2,3,4,5]) out[23]: 1Help on built-in function max in module __builtin__: Max (...) Max (iterable[, Key=func]), value #可迭代的对象 Max (A, B, C, ...) [, Key=func]) , value with a single iterable argument, return it largest item. #返回最大的参数 with and or more arguments, return The largest argument. in [+]: Max (' Hsdhsjd ', ' 5687 ', ' a ') #最长的一个Out []: ' HSDHSJD '
3. Get length Len ()
in [+]: s= ' 1234 ' in [[]: Len (s) #取字符创的长度Out []: 4help (len) to the built-in function Len in module __builtin__:len (...) Len (object), Integer #处理对象, returns the integer return the number of items of a sequence or collection. in [+]: Len ([up]) #取列表的元素个数, 2 out[31]: 2 in [Max]: Len ((' A ',)) #取元祖的元素个数, 1 out[30]: 1In [+]: Len ({' A ': 3, ' d ': 4}) #len () Statistical dictionaries have several pairs of elements out[32]: 2
4, quotient and remainder Divmod ()
in [+]: Help (Divmod) divmod (...) Divmod (x, y)-(quotient, remainder) Return the tuple ((x-x%y)/y, x%y). Invariant:div*y + mod = = x. (END) in [approx]: Divmod (5,2) out[36]: (2, 1) #商和余数
5. POW () Sub-party & Take surplus
In [PNS]: Help (POW)-on built-in function POW in module __BUILTIN__:POW (...) Pow (x, y[, z]), number with the arguments, equivalent to X**y. With three arguments, equivalent to (x**y)% Z, and May is more efficient (e.g. for longs). (END) In []: POW (2,3) #两个参数, the result is X's y-square out[38]: 8In [+]: Pow (2,3,3) #三个参数, the result is X's Y-side, then take a remainder, modulo out[40]: 2In [All]: Pow (2,3,4) out[3 9]: 0
6, round ()
The first step is to change the number to a floating point,
In the second step, there is no second parameter, rounding a number, by default, after the decimal point is. 0, with the second argument, the second parameter is to keep a few decimals
in [+]: Help (round) Help on built-in function round in module __builtin__:round (...) Round (number[, ndigits]), floating point number round a number to a given precision in decimal digits (default 0 digits). This is always returns a floating point number. Precision may negative. (END) In [round]: Print (12.145) 12.0In [si]: print round (12.145,3) 12.145In [in]: print round (12.145,4) 12.145
7. Can the callable () object be called?
In [63]: help (callable) help on built-in function callable in module __builtin__:callable (...) callable (object) -> bool #返回一个bool值 Return whether the object is callable (I.e., some kind of function). note that classes are callable, as are instances with a __call__ () method. In [64]: a = 123in [65]: callable (a) #字符a不可调用Out [65]: falsein [66]: def b (): ...: pass ...: in [67]: callable (b) #函数b可调用Out [67]: true in [69]: class a (object): #定义了一个对象也是可调用的, returning true ...: pass &Nbsp; ...: in [70]: callable (A) out[70]: true
8. Type ()
in [[+]: def b (): ...: Passin [[123In]: Print type (b) <type ' function ' >in []: "A" [All]: print type (a) <t ype ' int ' >in [[]: Print type ([]) <type ' list ' >
This article comes from "Plum blossom fragrance from bitter cold!" "Blog, be sure to keep this provenance http://daixuan.blog.51cto.com/5426657/1846987
Python Learning note 11-python built-in functions