enumerate, reversed, sorted, zipfilter, iter, mapabs, divmod, pow, roundbin, chr, hex, oct, ord
Draft for Information Only
Content
Python Built-in Conversion Functions abs() Parameters Remarks divmod() Parameters Remarks pow() Parameters Remarks round() Parameters Remarks Source and Reference
Python Built-in Conversion Functions
The Python interpreter has some built-in conversion functions.
abs()
abs(𝑥)
Parameters
abs()to return the absolute value.
𝑥to specify the number to be returned from.
Remarks
- The argument may be an integer or a floating point number.
- If the argument is a complex number, its magnitude is returned.
- If 𝑥 defines
__abs__(), abs(𝑥) returns 𝑥.__abs__().
divmod()
divmod(𝑎, 𝑏)
Parameters
divmod()to return a pair of numbers consisting of their quotient and remainder when using integer division.
𝑎
𝑏
Remarks
- Take two non complex numbers as arguments
- With mixed operand types, the rules for binary arithmetic operators apply.
- For integers, the result is the same as
(𝑎//𝑏, 𝑎%𝑏).
- For floating point numbers, the result is
(𝑞, 𝑎%𝑏), where 𝑞 is usually math.floor(𝑎/𝑏) but may be 1 less than that. In any case 𝑞*𝑏+𝑎%𝑏 is very close to 𝑎, if 𝑎%𝑏 is non-zero it has the same sign as 𝑏, and 0<=abs(𝑎%𝑏)<abs(𝑏)
pow()
pow(base, exp[, mod])
Parameters
pow()to return base to the power exp.
baseto specify the base to be computed from
expto specify the exp to be computed from
[mod]optional, to specify the mod to used in computation
Remarks
- Return base to the power exp; if mod is present, return base to the power exp, modulo mod (computed more efficiently than pow(base, exp) % mod). The two-argument form pow(base, exp) is equivalent to using the power operator: base**exp.
The arguments must have numeric types. With mixed operand types, the coercion rules for binary arithmetic operators apply. For int operands, the result has the same type as the operands (after coercion) unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. For example, 10**2 returns 100, but 10**-2 returns 0.01.
For int operands base and exp, if mod is present, mod must also be of integer type and mod must be nonzero. If mod is present and exp is negative, base must be relatively prime to mod. In that case, pow(inv_base, -exp, mod) is returned, where inv_base is an inverse to base modulo mod.
round()
round(number[, ndigits])
Parameters
round()to return the rounded version of a number.
numberto specify the number to be returned from
[ndigits]to specify the precision after the decimal point.
Remarks
- Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input.
For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). Any integer value is valid for ndigits (positive, zero, or negative). The return value is an integer if ndigits is omitted or None. Otherwise the return value has the same type as number.
For a general Python object number, round delegates to number.__round__.
Note
The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float. See Floating Point Arithmetic: Issues and Limitations for more information.
Source and Reference
©sideway
ID: 200702302 Last Updated: 7/23/2020 Revision: 0
|
|