第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

全部開(kāi)發(fā)者教程

Python 進(jìn)階應(yīng)用教程

Python 進(jìn)階應(yīng)用教程
01 Python 的對(duì)象和類(lèi) 02 Python 類(lèi)屬性和實(shí)例屬性 03 Python類(lèi)的構(gòu)造方法、析構(gòu)方法、實(shí)例方法 04 Python 類(lèi)的私有屬性和私有方法 05 Python 類(lèi)的繼承和多繼承 06 Python 類(lèi)實(shí)戰(zhàn) 07 Python 中的迭代器實(shí)現(xiàn)原理 08 Python 中的迭代器趣味實(shí)踐 09 Python 中的生成器實(shí)現(xiàn)原理 10 Python 中的生成器趣味實(shí)踐 11 Python 中的錯(cuò)誤和異常 12 Python 中的異常處理 13 Python 中的模塊 14 Python 標(biāo)準(zhǔn)庫(kù)之 os 模塊 15 Python 標(biāo)準(zhǔn)庫(kù)之 sys 模塊 16 Python 標(biāo)準(zhǔn)庫(kù)之 math 模塊 17 Python 標(biāo)準(zhǔn)庫(kù)之 random 模塊 18 Python 標(biāo)準(zhǔn)庫(kù)之 Json 模塊 19 Python 標(biāo)準(zhǔn)庫(kù) datetime 模塊 20 Python 中的常用第三方模塊 21 Python 中的命名空間 22 Python 中的作用域 23 Python 中的文件 IO 操作 24 Python 基礎(chǔ)實(shí)戰(zhàn) 25 Python 內(nèi)置函數(shù) 26 Python 中使用正則表達(dá)式 27 使用 Python 操作 MySQL 數(shù)據(jù)庫(kù) 28 使用 Python 操作 Mongo 數(shù)據(jù)庫(kù) 29 使用 Python 操作 Redis 數(shù)據(jù)庫(kù) 30 使用 Python 發(fā)送一封郵件 31 threading 之 Thread 的使用 32 threading 之 Lock 的基本使用 33 Python 生產(chǎn)者消費(fèi)者模型 34 Python 的內(nèi)存管理與垃圾回收 35 Python 領(lǐng)域運(yùn)用:網(wǎng)絡(luò)爬蟲(chóng) 36 Python 領(lǐng)域運(yùn)用:Web 開(kāi)發(fā) 37 Python 領(lǐng)域運(yùn)用:自動(dòng)化運(yùn)維 38 Python 領(lǐng)域運(yùn)用:自動(dòng)化測(cè)試

Python 標(biāo)準(zhǔn)庫(kù)之 math 模塊

1. 前言

math 模塊中包含了各種浮點(diǎn)運(yùn)算函數(shù),包括:

函數(shù) 功能
floor 向下取整
ceil 向上取整
pow 指數(shù)運(yùn)算
fabs 絕對(duì)值
sqrt 開(kāi)平方
modf 拆分小數(shù)和整數(shù)
fsum 計(jì)算列表中所有元素的累加和
copysign 復(fù)制符號(hào)
pi 圓周率
e 自然對(duì)數(shù)

2. math.floor(n)

函數(shù) math.floor(n) 的功能是對(duì)浮點(diǎn)數(shù) n 向下取整,示例如下:

>>> import math
>>> math.floor(1.5)
1
>>> math.floor(2.5)
2
>>> math.floor(-1.5)
-2
>>> math.floor(-2.5)
-3

3. math.ceil(n)

函數(shù) math.ceil(n) 的功能是對(duì)浮點(diǎn)數(shù) n 向上取整,示例如下:

>>> import math
>>> math.ceil(1.5)
2
>>> math.ceil(2.5)
3
>>> math.ceil(-1.5)
-1
>>> math.ceil(-2.5)
-2

4. math.pow(n, m)

函數(shù) math.pow(n, m) 的功能是指數(shù)運(yùn)算,n 是底數(shù),m 是指數(shù),示例如下:

>>> import math
>>> math.pow(2, 0)
1.0
>>> math.pow(2, 1)
2.0
>>> math.pow(2, 2)
4.0
>>> math.pow(2, 3)
8.0
>>> math.pow(2, 4)
16.0

5. math.fabs(n)

函數(shù) math.fabs(n) 的功能是計(jì)算 n 的絕對(duì)值,示例如下:

>>> import math
>>> math.fabs(1.23)
1.23
>>> math.fabs(-1.23)
1.23

6. math.sqrt(n)

函數(shù) math.sqrt(n) 的功能是計(jì)算 n 的平方根,示例如下:

>>> import math
>>> math.sqrt(4)
2.0
>>> math.sqrt(9)
3.0
>>> math.sqrt(16)
4.0

7. math.modf(n)

函數(shù) math.modf(n) 的功能是將浮點(diǎn)數(shù) n 拆分為小數(shù)和整數(shù),函數(shù)返回一個(gè)元組:

  • 元組的第 0 項(xiàng)是小數(shù)
  • 元組的第 1 項(xiàng)是整數(shù)

示例如下:

>>> import math
>>> math.modf(3.14)
(0.14, 3.0)
>>> tuple = math.modf(1949.1001)
>>> tuple[0]
0.1001
>>> tuple[1]
1949
  • 在第 3 行
    • 0.14 是 3.14 的小數(shù)部分
    • 3.0 是 3.14 的整數(shù)部分
  • 在第 6 行,0.1001 是 1949.1001 的小數(shù)部分
  • 在第 6 行,1949 是 1949.1001 的整數(shù)部分

8. math.fsum(list)

函數(shù) math.fsum(list) 的功能是計(jì)算列表中所有元素的累加和,示例如下:

>>> import math
>>> math.fsum([1, 2, 3])
6.0
>>> math.fsum((1, 2, 3)
6.0
  • 在第 2 行,計(jì)算列表 [1, 2, 3] 中 3 個(gè)元素的累加和
  • 在第 4 行,計(jì)算元組 (1, 2, 3) 中 3 個(gè)元素的累加和

9. math.copysign(a, b)

函數(shù) math.copysign(a, b) 的功能是將參數(shù) b 的正負(fù)符號(hào)復(fù)制給第一個(gè)數(shù),示例如下:

>>> import math
>>> math.copysign(2, -1)
-2.0
>>> math.copysign(-2, 1)
2.0

10. math.pi

函數(shù) math.pi 的功能是圓周率常量,示例如下:

>>> import math
>>> math.pi
3.141592653589793

11. math.e

函數(shù) math.e 的功能是自然對(duì)數(shù)常量,示例如下:

>>> import math
>>> math.e
2.718281828459045