Python標準庫:內建函數abs(x),pythonabs
返回數位絕對值。參數可以是整數或浮點數。如果參數是複數,則返回複數的模。因此abs()函數的注意點就是複數的不一樣計算方式。
例子:
#正整數print('abs(1):', abs(1))#負整數print('abs(-1):', abs(-1))#負浮點數print('abs(-10.5):', abs(-10.5))#複數print('abs(3+4j):', abs(3+4j))
輸出結果如下:
abs(1): 1
abs(-1): 1
abs(-10.5): 10.5
abs(3+4j): 5.0
在這個例子裡,1、-1是整數,-10.5是浮點數,3+4j是複數。
蔡軍生 QQ:9073204 深圳
python怎查看內建函數
import sys
print dir(sys.modules['__builtin__'])
誰舉例講解幾個python 內建函數
python的所有內建函數
abs() divmod() input() open() staticmethod()
all() enumerate() int() ord() str()
any() eval() isinstance() pow() sum()
basestring() execfile() issubclass() print() super()
bin() file() iter() property() tuple()
bool() filter() len() range() type()
bytearray() float() list() raw_input() unichr()
callable() format() locals() reduce() unicode()
chr() frozenset() long() reload() vars()
classmethod() getattr() map() repr() xrange()
cmp() globals() max() reversed() zip()
compile() hasattr() memoryview() round() __import__()
complex() hash() min() set() apply()
delattr() help() next() setattr() buffer()
dict() hex() object() slice() coerce()
dir() id() oct() sorted() intern()
我基本上都看過一遍,你希望知道哪一個的用法呢?