- Learning Python for Forensics
- Preston Miller Chapin Bryce
- 296字
- 2021-08-20 10:17:01
Integers and floats
The integer is another valuable data type that is frequently used—an integer is any whole positive or negative number. The float data type is similar, but allows us to use numbers requiring decimal-level precision. With integers and floats, we can use standard mathematical operations, such as: +, -, *, and /. These operations return slightly different results based on the object's type (for example, integer or float).
An integer uses whole numbers and rounding, for example dividing two integers will result in another whole number integer. However, by using one float in the equation, even one that has the same value as the integer will result in a float; for example, 3/2=1 and 3/2.0=1.5 in Python. The following are examples of integer and float operations:
>>> type(1010)
<class 'int'>
>>> 127*66
8382
>>> 66/10
6
>>> 10 * (10 - 8)
20
We can use ** to raise an integer by a power. For example, in the following section, we raise 11 by the power of 2. In programming, it can be helpful to determine the numerator resulting from the division between two integers. For this, we use the modulus or percent (%) symbol. With Python, negative numbers are those with a dash character (-) preceding the value. We can use the built-in abs() function to get the absolute value of an integer or float:
>>> 11**2
121
>>> 11 % 2 # 11 divided by 2 is 5.5 or 5 with a remainder of 1
1
>>> abs(-3)
3
A float is defined by any number with a decimal. Floats follow the same rules and operations as we saw with integers, with the exception of the division behavior described previously:
>>> type(0.123)
<class 'float'>
>>> 1.23 * 5.23
6.4329
>>> 27/8.0
3.375
- Rootkit和Bootkit:現(xiàn)代惡意軟件逆向分析和下一代威脅
- 等級保護(hù)測評理論及應(yīng)用
- 開發(fā)者的Web安全戒律:真實威脅與防御實踐
- Preventing Digital Extortion
- Learning Veeam? Backup & Replication for VMware vSphere
- 移動APT:威脅情報分析與數(shù)據(jù)防護(hù)
- 計算機網(wǎng)絡(luò)安全基礎(chǔ)(第5版)
- Digital Forensics with Kali Linux
- 可信計算3.0工程初步(第二版)
- 網(wǎng)絡(luò)安全與攻防入門很輕松(實戰(zhàn)超值版)
- 安全防御入門手冊
- 互聯(lián)網(wǎng)企業(yè)安全高級指南
- 網(wǎng)絡(luò)關(guān)鍵設(shè)備安全檢測實施指南
- 網(wǎng)絡(luò)安全實戰(zhàn)詳解(企業(yè)專供版)
- 網(wǎng)絡(luò)空間安全法律問題研究