Python Series two data types

Source: Internet
Author: User

1.1 Data types in Python

Python uses the object model to store data, each data type has a built-in class, and each new data is actually initialized to generate an object, with all the data being objects;

Object Three Special:

1. Identity: Memory address, can be obtained by ID ()

2. Type: Determines what type of value the object can hold, what action it can take, what rules to follow, and which can be obtained with type ()

3. Value: Real data saved by the object

1.2 Digital 1.2.1 int (integer)

1.在32位机器上,整数的位数为32位,取值范围为-2**31~2**31-1,即-2147483648~2147483647

2, on 64-bit systems, the number of integers is 64 bits, the value range is -2**63~2**63-1, that is -9223372036854775808~9223372036854775807

>>> 1010         ---------> Default decimal >>> oct (Ten) ' 012 '      ---------> Octal represents an Integer, the value preceded by a prefix "0" > >> hex ' 0xa '      ---------> hexadecimal denotes integer, prefix 0X or 0x before the number

The difference between python2.* and python3.* about integral type

python2.*
On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647

On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807
python3.* Plastic Length Unlimited

Integer factory function int ()

1.2.2 Long (L-integer)

1.跟C语言不同,Python的长整数没有指定位宽,

2.即:Python没有限制长整数数值的大小,但实际上由于机器内存有限,我们使用的长整数数值不可能无限大。

3.注意,自从Python2.2起,如果整数发生溢出,Python会自动将整数数据转换为长整数,所以如今在长整数数据后面不加字母L也不会导致严重后果了。

1.2.3 Float (float type)

1.浮点数用来处理实数,即带有小数的数字。

2.浮点表示的形式是小数,但小数不一定都是浮点型,23和52.3E-4是浮点数的例子。E标记表示10的幂。在这里,52.3E-4表示52.3 * 10-4。

1.2.4 Complex (plural)

1.复数由实数部分和虚数部分组成,一般形式为x+yj,其中的x是复数的实数部分,y是复数的虚数部分,这里的x和y都是实数。

注:Python中存在小数字池:-5 ~ 257

1.2.5 Boolean value

Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6, 01:54:25) [MSC v.1900-bit (AM
D64)] on Win32
Type "Help", "copyright", "credits" or "license" for more information.
>>> A = 0
>>> if A:print ("a")
...
>>> A = 1
>>> if A:print ("a")
...
A
>>>

1.2.6 number-related built-in functions

1.3 string

Python Series two data types

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.