Data type
A computer is a machine that can do mathematical calculations as the name implies, so a computer program can handle a variety of values. However, the computer can handle far more than the numerical value, but also can deal with text, graphics, audio, video, web and other kinds of data, different data, need to define different data types. In Python, there are several types of data that can be processed directly:
1: Integers
Python can handle integers of any size , including, of course, negative integers, and in a Python program, integers are represented in exactly the same way as mathematically, for example: 1,100,-8080,0, and so on.
Because the computer uses binary, it is sometimes more convenient to use hexadecimal notation for integers.
Hexadecimal is represented by a 0x prefix and 0-9,a-f , for example: 0XFF00,0XA5B4C3D2, and so on.
2: Floating point 10 instead of e
Floating-point numbers, which are decimals, are called floating-point numbers because, when represented by scientific notation, the decimal position of a floating-point number is variable, for example, 1.23x10^9 and 12.3x10^8 are equal. Floating-point numbers can be written in mathematical notation, such as 1.23,3.14,-9.01, and so on. But for very large or very small floating-point numbers, it must be expressed in scientific notation, the 10 is replaced with E, 1.23x10^9 is 1.23e9, or 12.3e8,0.000012 can be written 1.2e-5, and so on.
Integers and floating-point numbers in computershow to store internallyis different, integer arithmetic is always accurate (is division also accurate?). Yes! ), and the floating-point operation may have rounding errors.
3: String
strings are arbitrary text enclosed in ' or ', such as ' abc ', ' XYZ ', and so on. Note that the ' or ' itself is only a representation, not a part of the string, so the string ' abc ' only a,b,c these 3 characters.
4: Boolean value
A Boolean value is exactly the same as that of a Boolean algebra, and a Boolean value is onlyTrue, FalseThe two values, either True or false, can be used directly in PythonTrue, False indicates a Boolean value (note case), or it can be computed by Boolean operations.
Boolean values can be operated with and, or, and not.
The and operation is associated with an operation, and only the result of all true,and operations is True.
An OR operation is an operation, as long as one of the true,or operation results is True.
The not operation is a non-operation, which is a single-mesh operator that turns true to False,false to true.
5: null value
A null value is a special value in Python, withNoneSaid. None cannot be understood as 0, because 0 is meaningful, and none is a special null value.
In addition, Python provides alist, dictionaryand other types of data, and also allows you to create custom data types, we'll go back to
Python data type