Home  >  Article  >  Backend Development  >  How to enter numbers in python

How to enter numbers in python

silencement
silencementOriginal
2019-05-14 13:22:2947896browse

In programming, numbers are often used to record game scores, represent visual data, store web application information, etc. Python handles numbers differently depending on their usage. Since integers are the easiest to use, let’s first take a look at how Python manages them. Today we will learn how to enter numbers in python and the three number types among them!

How to enter numbers in python

In python, three number types are supported: integer type, floating point type and complex number type.

How to enter numbers in python:

1. First, open IDLE and see the >>> prompt

2. Behind the prompt Just enter the numbers directly, as shown below:

How to enter numbers in python

The output results are: integer 35, floating point number (decimal) 9.3, complex number 12 4j

How So, isn’t it very simple? Of course, python also supports multiple types of operations. Let’s introduce them separately

Integer types

##In Python, integers can be performed Add ( ), subtract (-), multiply (*) and divide (/) operations.

For example:

How to enter numbers in python

In a terminal session, Python directly returns the result of the operation. Python uses two multiplication signs to represent exponentiation operations:

How to enter numbers in python

Python also supports the order of operations, so you can use multiple operations in the same expression. You can also use parentheses to modify the order of operations and let Python perform operations in the order you specify, as follows:

How to enter numbers in python

Floating point type (decimal)

Python calls numbers with decimal points floating point numbers. This term is used in most programming languages ​​and refers to the fact that the decimal point can appear anywhere in a number. Every programming language must be carefully designed to handle floating-point numbers properly, ensuring that numbers behave normally regardless of the position of the decimal point.

Look at the example:

How to enter numbers in python

Plural type

z = a bj

a is the real part, b is the imaginary part, a and b are both floating point types, the imaginary part is represented by j or J

For example:

How to enter numbers in python

For complex numbers, you can use z.real to obtain the real part and z.imag to obtain the imaginary part.

How to enter numbers in python

The above is the input and operation of numbers in Python , log in to the php Chinese website to get more learning content!

The above is the detailed content of How to enter numbers in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more