Python data type (number)

Source: Internet
Author: User
Tags abs

 The article references the tutorial: Http://www.runoob.com/python/python-basic-syntax.html#commentform        
PythonVariable Type

The value that the variable is stored in memory. This means that there is a space in memory when creating variables.

Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.

Therefore, variables can specify different data types, which can store integers, decimals, or characters.

Standard data types

There are several types of data that can be stored in memory.

For example, a person's age can be stored in numbers, and his name can be stored in characters.

Python defines a number of standard types for storing various types of data.

Python has five standard data types:

    • Numbers (digital)
    • String (String)
    • List (lists)
    • Tuple (tuple)
    • Dictionary (dictionary)

Python numbers

Numeric data types are used to store numeric values.

They are immutable data types, which means that changing the numeric data type assigns a new object.

When you specify a value, the number object is created:

VAR1 = 1
VAR2 = 10

You can also use the DEL statement to delete references to some 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 var
Del Var_a, Var_b

Python supports four different types of numbers:

    • Integer (Int) -usually referred to as an integer or integral, is a positive or negative integer, with no decimal points.
    • long integers -an integer with an infinite size, and an integer that ends with an uppercase or lowercase L.
    • float (floating point real values) -floating-point types consist 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 numbers) -complex numbers are made up of real and imaginary parts, and can be represented by a + BJ, or complex (A, a, b), where both the real and imaginary part of a complex number are floating-point types.

Instance

Examples of some numeric types:

int Long float Complex
10 51924361L 0.0 3.14j
100 -0x19323l 15.20 45.j
-786 0122L -21.9 9.322e-36j
080 0xDEFABCECBDAECBFBAEl 32.3e+18 .876j
-0490 535633629843L -90. -.6545+0j
-0x260 -052318172735l -32.54e100 3e+26j
0x69 -4721885298529l 70.2E-12 4.53e-7j

    • Long integers can also use lowercase l, but it is recommended that you use uppercase L to avoid confusion with the number 1. Python uses L to display the long integer type.
    • Python also supports complex numbers, which 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.
Python math functions
function return value (description)
ABS (x) Returns the absolute value of a number, such as ABS (-10) returns 10
Ceil (x) Returns the top integer of a number, such as Math.ceil (4.1) returns 5
CMP (x, y) If x < y returns 1, if x = = y returns 0, if x > y returns 1
EXP (x) Returns the x power of E (ex), such as MATH.EXP (1) returns 2.718281828459045
Fabs (x) Returns the absolute value of a number, such as Math.fabs (-10) returns 10.0
Floor (x) Returns the lower integer of a number, such as Math.floor (4.9) returns 4
Log (x) If Math.log (MATH.E) returns 1.0,math.log (100,10) returns 2.0
LOG10 (x) Returns the logarithm of x with a base of 10, such as MATH.LOG10 (100) returns 2.0
Max (x1, x2,...) Returns the maximum value of a given parameter, which can be a sequence.
Min (x1, x2,...) Returns the minimum value for a given parameter, which can be a sequence.
MODF (x) Returns the integer portion of x and the fractional part, the two-part numeric symbol is the same as x, and the integer part is represented by a floating-point type.
Pow (x, y) The value after the x**y operation.
Round (x [, N]) Returns the rounded value of the floating-point number x, if given an n value, that represents the digits rounded to the decimal point.
sqrt (x) Returns the square root of a number X

Python 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:

function Description
Choice (seq) Pick an element randomly from the elements of the sequence, such as Random.choice (range (10)), and randomly pick an integer from 0 to 9.
Randrange ([Start,] stop [, step]) Gets a random number in the collection that increments by the specified cardinality from the specified range, and the base default value is 1
Random () Randomly generates the next real number, which is within the [0,1] range.
Seed ([x]) Changes the seeding seed of the random number generator. If you don't know how it works, you don't have to specifically set Seed,python to help you choose Seed.
Shuffle (LST) Randomly sort all elements of a sequence
Uniform (x, Y) Randomly generates the next real number, which is within the [x, Y] range.

Python Trigonometric functions

Python includes the following trigonometric functions:

function Description
ACOs (x) Returns the inverse cosine radian value of x.
ASIN (x) Returns the arc value of the arc sine of X.
Atan (x) Returns the arc tangent value of x.
Atan2 (y, x) Returns the inverse tangent value of the given X and Y coordinate values.
COS (x) Returns the cosine of the arc of X.
Hypot (x, y) Returns Euclidean norm sqrt (x*x + y*y).
Sin (x) Returns the sine of the X radian.
Tan (x) Returns the tangent of x radians.
Degrees (x) Convert radians to angles, such as degrees (MATH.PI/2), returns 90.0
Radians (x) Convert an angle to radians

Python Math Constants
Constants Description
Pi Mathematical constant Pi (pi, usually denoted by π)
E The mathematical constant e,e is the natural constant (natural constant).

Python data type (number)

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.