Introduction to four numeric types (int, long, float, complex) in python, pythoncomplex

Source: Internet
Author: User

Introduction to four numeric types (int, long, float, complex) in python, pythoncomplex

Python supports four different numeric types, including int (integer) long (long integer) float (floating point actual value) complex (plural ), this article introduces four numeric types of python to coders. For more information, see.

The numeric data type stores the numeric value. They are unchangeable data types, which means changing the numeric data type results in a new assigned object value.
Number object is created when you assign a value to them. For example:

var1 = 1var2 = 10

You can also delete the numeric object reference by using the del statement.
The syntax of 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): a positive or negative integer without a decimal point.
  • Long(Long integer): Or a desire, an integer of an infinite size. In this way, an integer and an L in upper or lower case are written.
  • Float(Actual floating point value): A colored car that represents a real number. The decimal part is divided by the integer part and the decimal part in writing. Floats may also be in scientific notation with E or Directive 10th power é (2.5e2 = 2.5 × 102 = 250 ).
  • Complex(Plural): in the form of + BJ, where a and B are the square root of-1 represented by colored cars and J (or J) (this is a virtual number ). A is the real numeric part, and B is the virtual part. Do not use Python programming for plural numbers.

Here are some examples of numbers:

Int Long Float Complex
10 51924361L 0.0 3.14j
100 -0x19323L 15.20 45. j
-786 0122L -21.9 9.322e-36j
080 0 xDEFABCECBDAECBFBAEl 32.3 + e18 . 876j
-0490 535633629843L -90. -. 6545 + 0J
-0x260 -052318172735L -32.54e100 3e + 26J
0x69 -4721885298529L 70.2-E12 4.53e-7j

 

  • Python allows you to use lower-case letters with a length of L, but we recommend that you use only one upper-case letter L to avoid confusion with number 1. The python long integer displays an uppercase letter (L.
  • A complex number is composed of an ordered pair of a real floating point number + BJ, where a is the real part and B is the imaginary part of the plural.

 

Numeric type conversion:

The numeric conversion in Python contains a common mixed expression of rating types. But sometimes you need to explicitly force a number from one type to another operator or function parameters to meet the requirements.

  • IntType (X) converts X to a common integer.
  • Long(X) converts X to a long integer.
  • FloatType (X) converts X to a floating point number.
  • Complex(X) converts X to a complex number from x to zero in Part x and imaginary. Complex types (X, Y) convert the nth and imaginary verbs of x and y. X and y are numeric expressions with the built-in number function:

 

Address: http://www.manongjc.com/article/973.html

Python related information:

Basic Python syntax

Python object-oriented programming example

Python variables and variable types

Introduction to Python operators and priority instances

Python if else statement example

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.