python007 Python3 Digit (number)

Source: Internet
Author: User
Tags integer division mathematical constants mathematical functions

var1 = 1VAR2 = 10

You can also use the DEL statement to delete references to some numeric objects.
The syntax for the DEL statement is:

Del Var1[,var2[,var3[....,varn] []]

You can delete a reference to a single or multiple objects by using the DEL statement, for example:

Del Vardel var_a, Var_b

Python supports three different numeric types:

    • Integer (INT)-usually referred to as an integer or integral, is a positive or negative integer, with no decimal points. The Python3 integral type is not limited in size and can be used as a long type, so Python3 does not have a long type of Python2.
    • Float (float)-floating-point type consists of integral and fractional parts, and floating-point types can also be represented using scientific notation (2.5e2 = 2.5 x 102 = 250)
    • Complex numbers ((complex))-complex numbers are composed of real and imaginary parts, and can be represented by a + BJ, or complex (a, b), where both the real and imaginary part of a complex number are floating-point types.

We can use hexadecimal and octal to represent integers:

>>> number = 0xa0f # hex >>> number2575>>> number=0o37 # octal >>> number31

    • Python supports complex numbers, which consist of real and imaginary parts, and can be represented by a + BJ, or complex (a, b), where both the real and the imaginary part of a complex number are floating-point types.

Python Numeric Type conversions
Sometimes, we need to convert the data-built type into the data type, and you just need to use the data type as the function name.

    • int (x) converts x to an integer.
    • Float (x) converts the x to a floating-point number.
    • Complex (x) converts x to a complex number, the real part is x, and the imaginary part is divided into 0.
    • Complex (x, Y) converts X and Y to a complex number, the real part is x, and the imaginary part is Y. X and y are numeric expressions.

The following instance converts a floating-point variable A to an integer:

>>> a = 1.0>>> int (a) 1


Python Numeric operations
The Python interpreter can be used as a simple calculator, and you can enter an expression in the interpreter that will output the value of the expression.
The syntax of an expression is straightforward: +,-, * and/and other languages (such as Pascal or C). For example:

>>> 2 + 24>>> 50-5*620>>> (50-5*6)/45.0>>> 8/5 # always returns a floating-point number 1.6

Note: the results of the floating point operations on different machines may vary.
In integer division, Division (/) always returns a floating-point number, and if you want only the result of an integer, discard the possible fractional portion, you can use the operator//:

>>> 17/3 # Integer division returns floating-point 5.666666666666667>>>>>> 17//3 # Integer division Returns the result of rounding down 5>>> 17 3 #% operating The remainder of the division is returned 2>>> 5 * 3 + 2 17

The equals sign (=) is used to assign a value to a variable. After assignment, the interpreter does not display any results except for the next prompt.
>>> width = 20
>>> height = 5*9
>>> Width * height
900
Python can use the * * operation to perform a power operation:

>>> 5 * * 2 # 5 Squared 25>>> 2 * * 7 # 2 7-Time Square 128

A variable must be "defined" (that is, given a variable value) before it can be used, or an error will occur:

>>> N # Try to access an undefined variable traceback (most recent call last): File "<stdin>", line 1, in <module>nameerror:n Ame ' n ' is not defined

Different types of number blending operations convert integers to floating-point numbers:

>>> 3 * 3.75/1.57.5>>> 7.0/23.5

In interactive mode, the result of the last expression output is assigned to the variable _. For example:

>>> tax = 12.5/100>>> Price = 100.50>>> Price * tax12.5625>>> price + _113.0625>& Gt;> Round (_, 2) 113.06

Here, the _ variable should be treated as a read-only variable by the user.

Mathematical functions


Random number function

Random numbers can be used in mathematics, games, security and other fields, but also often embedded in the algorithm to improve the efficiency of the algorithm and improve the security of the program.
Python contains the following common random number functions:

Trigonometric function
Python includes the following trigonometric functions:

Mathematical constants

python007 Python3 Digit (number)

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.