TOCPythonLanguageCode LineCode BlockFunctionsCommon PackagesResource and Link Draft for Information Only
ContentPython Integer Manipulation
Python Integer ManipulationFuction int()Return an integer object constructed from a number or string x, or return 0 if no arguments are given. If x defines __int__(), int(x) returns x.__int__(). If x defines __index__(), it returns x.__index__(). If x defines __trunc__(), it returns x.__trunc__(). For floating point numbers, this truncates towards zero. If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in radix base. Optionally, the literal can be preceded by + or - (with no space in between) and surrounded by whitespace. A base-n literal consists of the digits 0 to n-1, with a to z (or A to Z) having values 10 to 35. The default base is 10. The allowed values are 0 and 2–36. Base-2, -8, and -16 literals can be optionally prefixed with 0b/0B, 0o/0O, or 0x/0X, as with integer literals in code. Base 0 means to interpret exactly as a code literal, so that the actual base is 2, 8, 10, or 16, and so that int('010', 0) is not legal, while int('010') is, as well as int('010', 8).Syntaxclass int([x])
Function round()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.Syntaxround(number[, ndigits])
Fuction numpy.ceil()Return the ceiling of the input, element-wise. The ceil of the scalar x is the smallest integer i, such that i >= x. It is often denoted as ⌈x⌉.Syntaxnumpy.ceil(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'ceil'>
Function numpy.floor()Return the floor of the input, element-wise. The floor of the scalar x is the largest integer i, such that i <= x. It is often denoted as ⌊x⌋.Syntax numpy.floor(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'floor'>
Function numpy.fix()Round to nearest integer towards zero. Round an array of floats element-wise to nearest integer towards zero. The rounded values are returned as floats.Syntaxnumpy.fix(x, out=None)
Function numpy.trunc()Return the truncated value of the input, element-wise. The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the fractional part of the signed number x is discarded.Syntaxnumpy.trunc(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'trunc'>
Function numpy.rint()Round elements of the array to the nearest integer.Syntaxnumpy.rint(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'rint'>
Summarized Examples"Number-2.0-1.7-1.6-1.5-1.4-1.0-0.7-0.20.00.20.71.01.41.51.61.72.0−n+
int-2-1-1-1-1-100000111112→.0←
round-2-2-2-2-1-1-10001112222←.5→
numpy.ceil-2.-1.-1.-1.-1.-1.-0.-0.0.1.1.1.2.2.2.2.2.→.0→
numpy.floor-2.-2.-2.-2.-2.-1.-1.-1.0.0.0.1.1.1.1.1.2.←.0←
numpy.fix-2.-1.-1.-1.-1.-1.-0.-0.0.0.0.1.1.1.1.1.2.→.0←
numpy.trunc-2.-1.-1.-1.-1.-1.-0.-0.0.0.0.1.1.1.1.1.2.→.0←
numpy.rint-2.-2.-2.-2.-1.-1.-1.-0.0.0.1.1.1.2.2.2.2.←.5→
Source and Reference
©sideway ID: 210900017 Last Updated: 9/17/2021 Revision: 0 Latest Updated Links
|
Home 5 Business Management HBR 3 Information Recreation Hobbies 8 Culture Chinese 1097 English 339 Reference 79 Computer Hardware 249 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 Set 1 Logic 1 Algebra 84 Number Theory 206 Trigonometry 31 Geometry 34 Calculus 67 Engineering Tables 8 Mechanical Rigid Bodies Statics 92 Dynamics 37 Fluid 5 Control Acoustics 19 Natural Sciences Matter 1 Electric 27 Biology 1 |
Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019