Sideway
output.to from Sideway
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


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 226

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2023 Sideway . All rights reserved Disclaimers last modified on 06 September 2019