Detailed python four types of numeric (Int,long,float,complex) differences and conversion methods

Source: Internet
Author: User
Tags square root uppercase letter
Python supports four different numeric types, including int (integer) long (Long integer) float (floating point actuals) complex (complex number),

Numeric data types store values. They are immutable data types, which means changing the value of the numeric data type results in a newly allocated object.

Number objects are created when you assign them a value. For example:

var1 = 1VAR2 = 10

You can also delete a reference to a numeric object, using the DEL statement.

The syntax for the DEL statement is:

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

You can use the DEL statement to delete a single object or multiple objects.

For example:

Del Vardel var_a, Var_b

Python supports four different numeric types:

int (signed integer): usually referred to as an integer or an integer, without a positive or negative integer of the decimal point.

long (Long integer): or desired, an infinite-sized integer, so write an integer and a uppercase or lowercase l.

Float (floating point actuals): floats, representing real numbers, fractions divided by integers and fractional parts written. Floats may also be in the scientific notation with e or the instruction of the 10-square é (2.5e2= 2.5x102=250).

complex (plural): + BJ form, where a, B is a float and J (or J) represents the square root of 1 (this is an imaginary number). A is the true number part, and B is the imaginary one. The complex number is not programmed with Python.

Python allows you to use the lowercase of long l, but it is recommended that you use only one uppercase letter L to avoid confusion with the number 1. Python Long integer displays an uppercase letter L.

• A complex number consists of an ordered pair of real floating-point numbers + BJ, where A is real and B is the imaginary part of the complex representation.

Numeric Type conversions:

The Python digital conversion interior contains a common evaluation type of mixed expression. But sometimes, you need to explicitly force a number from one type to another operator or function parameter to meet the requirements.

The int type (x) converts x to a normal integer.

Long (x) converts x to a long integer.

The float type (x) converts x to floating-point numbers.

The conversion of complex (x) with True x and imaginary parts is zero to a complex number. The type complex (x, Y) converts X and Y to the X and the imaginary part y complex numbers. X and y are numeric expression built-in number functions

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.