python data types

Data type in Python

Computers, as the name implies, are machines that can do mathematical calculations. Therefore, computer programs can handle various values of course. However, computers can handle far more than just numerical values. They can also process various data such as text, graphics, audio, video, and web pages. Different data need to define different data types. In Python, there are several types of data that can be processed directly:

First, the integer

Python can handle integers of any size, including negative integers. In Python programs, integer representations are exactly the same as mathematical ones, such as:1100-80800, and so on.

Because computers use binary, it is convenient to use hexadecimal to represent integers. Hexadecimal is 0xprefixed with 0-9, af, for example: 0xff000xa5b4c3d2, and so on.

Second, the floating point number

Floating-point numbers are also decimals. They are called floating-point numbers because the position of the decimal point of a floating-point number is variable according to scientific notation. For example, 1.23×10 ^9 and 12.3×10 ^8 are equal. Floating point numbers can be written mathematically, such as 1.233.14-9.01, and so on. But for large or small floating point numbers, you must use scientific notation to replace 10 with e, 1.23×10 ^9 is 1.23e9 , or 12.3e8 , 0.0001212 can be written as 1.2e-5 , and so on.

Integers and floating-point numbers are stored differently inside the computer. Integer operations are always accurate (is it accurate and accurate? Yes!), while floating-point operations may have rounding errors.

Third, the string

A string is any text enclosed in ''or ""enclosed, such as ‘abc’ , “xyz”, and so on. Note that  or ‘” itself is just a representation, not part of a string, so strings 'abc'only have a,b,cthese 3 characters.

Fourth, the Boolean value

Boolean algebra and Boolean value indicating exactly the same, only a Boolean value TrueFalsetwo kinds of value, either True, either False, in Python, can be directly used TrueFalserepresents a Boolean value (note the case), can also be calculated by Boolean operators .

Boolean values may be used andorand notoperation.

andThe operation is an AND operation, only all of which are True, and the result of the operation is True.

orThe operation is OR, as long as one of them is True, the result of the or operation is True.

notThe operation is a non-operation, it is a monocular operator, turning True into False and False to True.

Five, null

A null value is a special value in Python, Noneexpressed in terms of. None can 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, dictionaries, etc., and also allows the creation of custom data types, we will continue to talk about it later.

Leave a Reply

Your email address will not be published. Required fields are marked *