Everything in Python is an object, and objects are created based on classes.
This article focuses on some of the main data types in Python.
Integer (int Class)
Tip: All of the following methods are methods in the class, the first argument is self, and unity is not written.
The methods that are included are:
1, Bit_length ()#返回表示该数字时占用的最少位数
>>> (bit_length).
9
2. ABS (x) #返回绝对值
>>> ABS (-9)
9
3, __add__ (y)#等同于加法
x.__add__ (y) <==> x+y
4, __and__ (y)#求交集的意思
x.__and__ (y) <==> x&y
>>> x=5
>>> y=4
>>> x.__and__ (y)
4
5. CMP (x, y) #比较两个数大小
>>> CMP (10,5)
1 #大于返回1
>>> CMP (10,11)
-1 #小于返回-1
>>> CMP (10,10)
0 #等于返回0
6, Divmod (x, y): #相除, a tuple consisting of quotient and remainder, often used in page pagination
>>> Divmod (88,9)
(9, 7) #88除以9 Quotient is 9 of the 7
>>> Divmod (88,8)
(11, 0) #88除以8 Quotient is 11 of the 0
7, hash (x) #在字典查找中, hash value is used to quickly compare the dictionary keys. Two values if equal, the hash value is also equal.
>>> Hash (123)
123
8, int (x)#转换为整数
9, Long (x)#转换为长整数
10, float (x)#转换为浮点类型
>>> Float (12)
12.0
11, Hex (x)#返回当前数的 hexadecimal representation
12, Oct (x)#返回当前值的 octal representation
13. Pow (x,y) #次方
>>> Pow (2,3)
8
Next article:
String (str Class)
This article from "A rookie on the Sky" blog, please be sure to keep this source http://rmeos.blog.51cto.com/761575/1710203
Python Basics (int Class)