Home>Article>Backend Development> What are the data types in python?

What are the data types in python?

silencement
silencement Original
2019-06-10 13:42:35 6258browse

What are the data types in python?

In Python, the basic data types can be mainly divided into the following types:

1. Number (Number);

2. String;

3. List;

4. Dictionary;

5. Tuple;

Today we will take an in-depth look at the data type of Number.

In Python3, the supported number types are:

1.int--integer type

2.float--floating point type

3.bool--Boolean

4.fractions--fraction

5.complex--complex number

Declaration:

The left side is the variable name, and the right side is the value to be assigned. There is no need to specify the data type in front, and Python can automatically distinguish whether it is an integer or a floating point type through the assigned value;

For example:

>>>a=100 #将100赋给a >>>b=-200 #将-200赋给b >>>c=2.9 #将2.9赋给c >>>d=True #将True赋给d >>>e=complex(2,3) #将复数(2+3j)赋给e

There is also such a declaration of

>>>a,b,c=2,3,4 #一次性声明多个 >>>a,b,c,d=1,2.3,True,complex(2,3) #也可以这样

. The standard library fractions must be introduced before the declaration:

>>>import fractions>>>x=fractions.Fraction(1,10)>>>print(x)

The above is the detailed content of What are the data types 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