selfteaching / the-craft-of-selfteaching

One has no future if one couldn't teach themself.
15.13k stars 16.3k forks source link

Part.1.E.4.functions.ipynb 中 divmod函数的返回值说明 #1011

Open jingmian opened 3 years ago

jingmian commented 3 years ago

在作者解释 divmod函数时提到 它的返回值,是一个元组(Tuple,至于这是什么东西,后面讲清楚),其中包括两个值,第一个是商,第二个是余 —— 此为该函数的输出。 而我根据英文文档 ,找不到Tuple返回值这样的关键字,我们新手又如何在这个英文文档中,知道它是返回 元组 呢?

Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using integer division. With mixed operand types, the rules for binary arithmetic operators apply. For integers, the result is the same as (a // b, a % b). For floating point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that. In any case q * b + a % b is very close to a, if a % b is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b).
bing90740 commented 3 years ago

用python内建函数type,可以看到数据类型。

type(divmod(11,3))

image