Skip to content

Integer

一句话解释

integer 是 整个 数字 — 正, 负, or 零 — 使用 否 fractional or decimal 部分.

用大白话说

integer 是一种number without a decimal point。 Examples include 5, -3, 0, 42, and -1000. Integers are used for counting, indexing, and any situation where fractional values do not make sense.

大多数languages distinguish integers from floating-point numbers (floats), which have decimal parts. For example, 7 is an integer, but 7.5 is a float. In JavaScript, all numbers are technically floats, but in languages like Python, Java, and C, integers and floats are distinct types.

Integers are efficient for the computer to store and calculate with. They are the default choice for loop counters, array indices, and anything you count or enumerate.

示例

python
age = 25          # integer
temperature = -5  # negative integer

print(type(age))  # <class 'int'>
print(7 / 2)      # 3.5 (float, not integer)
print(7 // 2)     # 3  (integer division)

In Python, int 是 distinct 类型. Integer division // discards fractional 部分.

常见混淆

  • 容易混淆的对象: float

    关键区别: integer 是 整个 数字 使用 否 decimal 部分 (7); float 有 fractional 部分 (7.5). 操作 如 7/2 可能 produce float 偶数 从 integer 输入.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表