Basic introduction to Python 0 (6)-------numeric type

Source: Internet
Author: User

int, float type

Python's int, float type has no explicit scope restrictions relative to other languages, Python

The value of the int, float type can be stored is determined by the hardware

Decimal can be directly written, octal is 0o beginning, hex 0x starts, binary 0b starts

Mathematical operators

+ Plus

-Minus

* Multiply if the string is multiplied by a number to indicate that the string repeats several times

* * Calculation of the sub-party

/except

Divisible

% take-up

Built-in functions and tool modules for numeric values

Built-in functions

Int () converts to int (value, binary) example: Int ("1101", 2) Int ("177", 8) int ("9ff", 16)

Float () converted to float type value

Round () rounding

Bin (number) is converted to binary

Oct (number) converted to octal

Hex (number) converted to hex

Tool module math, importing modules

functions under the Math module

Floor () to go down to the whole, in a small direction to take "3..14 obtained is 3, -3..14 obtained is-4"

Trunc () to 0 in the direction of the value "3.14 obtained is 3, 3.14 obtained is-3"

Ceil () rounded up, toward the large direction "3.14 obtained is 4, 3.14 obtained is 3"

Math.PI can get pi value

Pow (2,4) 2 of the four-time square

SQRT (81) Open Square

Precision processing of floating-point type

Under normal circumstances, you should get 0, but you get a different value. This is the problem of precision.

The decimal module solves this problem of precision, which provides a decimal class, which takes into the form of a string when passing a value

Another way to import

The nature of Bool

BOOL only true vs. false corresponds to 1 and 0

Built-in function bool () converts a value to a bool value

0, 0.0, [], {}, ', None will be converted to false

Basic introduction to Python 0 (6)-------numeric type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.