Python標準庫:內建函數abs(x),pythonabs

來源:互聯網
上載者:User

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()

我基本上都看過一遍,你希望知道哪一個的用法呢?
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.