Home  >  Article  >  Backend Development  >  What data types are there in Python language?

What data types are there in Python language?

(*-*)浩
(*-*)浩Original
2019-10-31 14:06:537614browse

In Python, the following data types can be processed directly:

What data types are there in Python language?

1. Integer

Python can handle integers of any size, including negative integers of course. In Python programs, integers are expressed exactly the same as in mathematics, such as: 1, 100, -8080, 0, etc. (Recommended learning: Python video tutorial)

Since computers use binary, it is sometimes more convenient to use hexadecimal to represent integers. Hexadecimal uses the 0x prefix and 0-9 , a-f means, for example: 0xff00, 0xa5b4c3d2, etc.

2. Floating point numbers

Floating point numbers are also decimals. They are called floating point numbers because when expressed in scientific notation, the decimal point of a floating point number The position is variable, for example, 1.23x10^9 and 12.3x10^8 are equal. Floating point numbers can be written mathematically, such as 1.23, 3.14, -9.01, etc. But for very large or very small floating point numbers, they must be expressed in scientific notation. Replace 10 with e. 1.23x10^9 is 1.23e9, or 12.3e8, 0.000012 can be written as 1.2e-5, and so on.

The way integers and floating-point numbers are stored inside the computer are different. Integer operations are always accurate (is division also accurate? Yes!), while floating-point operations may have rounding errors.

3. String

A string is any text enclosed in '' or '', such as 'abc', 'xyz', etc. Please note that '' or '' itself is just a way of expression, not part of the string. Therefore, the string 'abc' only has 3 characters: a, b, and c.

4. Boolean value

The representation of Boolean value and Boolean algebra is exactly the same. A Boolean value has only two values: True and False, either True or False , in Python, you can directly use True and False to represent Boolean values ​​(please pay attention to the case), or you can calculate them through Boolean operations.

Boolean values ​​can be operated with and, or and not.

The and operation is an AND operation. Only when everything is True, the result of the AND operation is True.

The or operation is an OR operation. As long as one of them is True, the result of the or operation is True.

The not operation is a negation operation. It is a unary operator that turns True into False and False into True.

5. Null value

The null value is a special value in Python, represented by None. None cannot be understood as 0, because 0 is meaningful, and None is a special null value.

In addition, Python also provides a variety of data types such as lists and dictionaries, and also allows the creation of custom data types.

The above is the detailed content of What data types are there in Python language?. 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