Python data type (Learning Note II)
In Python, there are several types of data that can be processed directly:
(1) Integer
Python can handle integers of any size, including, of course, negative integers, which are represented in the program in the same way as mathematically, for example
such as: 1, 100, ‐8080, 0, and so on.
Computer because of the use of binary, so, sometimes hexadecimal notation is more convenient, hexadecimal with 0x prefix and 0-9,a-f , example
such as: 0xff00, 0xa5b4c3d2, and so on.
(2) floating point number
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 and 12.3x10 are equal. Floating-point numbers can be mathematically written, such as 1.23, 3.14, ‐9.01, and so on. But for very large or very small floating-point numbers, you must use the scientific notation, the 10 with e substitution , 1.23x10 is 1.23e9, or 12.3e8, 0.000012 can be written 1.2e‐5, and so on.
Note:
1) integer and floating-point numbers are stored inside the computer in a different way.
2) integer arithmetic is always accurate (is division also accurate?) YES), and floating-point arithmetic may have rounding errors.
(3) string
strings are arbitrary text enclosed in ' or ', such as ' abc ', ' XYZ ', and so on.
Please note:
1) "or" "itself is only a representation, not a part of the string, so the string ' abc ' has only A, B, C of 3 characters.
2) If ' itself is also a character, then you can use "", such as "I m OK" contains the characters are I, ', M, Space, O, K these 6 characters.
3) What if the inside of a string contains both ' and contains '? You can use the escape character \ To identify, for example:
' I\ ' m \ ' ok\ '! '
The string content represented is:
I ' m "OK"!
As follows:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/92/A4/wKiom1kBjNKTf4cSAAASE8egkQM536.png "title=" 22. PNG "alt=" Wkiom1kbjnktf4csaaase8egkqm536.png "/>
As you can see, Python will report syntax errors when using print ' I ' m \ "Ok\"!
(4) Boolean value
The Boolean value is exactly the same as the Boolean algebra, with a Boolean value of only true, false two, or true, or false, in Python, which can be used to indicate a Boolean value directly with True, false (note case), or by Boolean operations:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/92/A3/wKioL1kBjf6Q-CVuAAAJQWs8dAg860.png "title=" 22. PNG "alt=" Wkiol1kbjf6q-cvuaaajqws8dag860.png "/>
Boolean values can be operated with and, or, and not.
The and operation is with an operation, and only all is true, and the result of the and operation is true:
>>> true and True
True
>>> True and False
False
>>> false and False
False
An OR operation is a or operation, as long as one of them is true, the or operation results in true:
>>> true or True
True
>>> True or False
True
>>> false or False
False
The not operation is a non-operation, which is a single-mesh operator that turns true to false and false to true:
>>> not True
False
>>> not False
True
(5) Null value
The null value is a special value in Python, denoted 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, such as lists, dictionaries, and so on, and also allows you to create custom data types.
This article is from the "Hand of the Paladin Control" blog, please make sure to keep this source http://wutengfei.blog.51cto.com/10942117/1920013
Python data type (Learning Note II)