Talk briefly about several common data types in Python

  • 2020-05-26 09:31:19
  • OfStack

A computer is, by definition, a machine that can do mathematical calculations, so it stands to reason that a computer program can process all kinds of numerical values. However, computers can process much more than just Numbers. They can also process text, graphics, audio, video, web pages, and other kinds of data. Different types of data need to be defined. In Python, there are several types of data that can be processed directly:

1. The integer

Python can handle integers of any size, including negative integers. In the Python program, integers are represented and mathematically written 1 to 1, such as: 1,100, -8080, 0, and so on.

Computer due to the use of 2 base, so, sometimes in 106 hexadecimal integer is more convenient, 106 into the system using 0 x prefix and 0-9, a - f says, for example: 0 xff00, 0 xa5b4c3d2, and so on.

2. The floating point number

Floating point Numbers are also known as decimals. They are called floating point Numbers because the decimal point position of a floating point number is variable in scientific notation. For example, 1.23x10^9 is the same as 12.3x10^8. Floating point Numbers can be written mathematically, such as 1.23, 3.14, -9.01, and so on. But for very large or small floating point Numbers, you have to use the scientific notation, replace 10 with e, 1.23x10^9 is 1.23e9, or 12.3e8, 0.000012 can be written as 1.2 e-5, and so on.

Integers and floating point Numbers are stored in computers in different ways, and integer operations are always exact. Yes!) , while floating point arithmetic may have a rounding error of 4 and 5.

3. The string

A string is any text that is enclosed by "or", such as 'abc', 'xyz', and so on. Note that '' or '' is itself just a representation, not part 1 of the string, so the string 'abc' has only three characters: a, b, c.

4. The Boolean value

The Boolean value and Boolean algebra are completely 1, a Boolean value only True, False two values, either True, or False, in Python, you can directly use True, False to represent the Boolean value (please pay attention to the case), also can be calculated by Boolean operation.

Boolean values can be calculated using and, or, and not.

The and operation is the sum operation, only if all are True, and operation result is True.

or operations are or operations, and as long as one of them is True, or results in True.

The not operation is a non-operation, which is a single unary operator that turns True into False and False into True.

5. A null value

Null 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 provides a variety of data types, including lists, dictionaries, and the ability to create custom data types, which we'll discuss later


Related articles: