int实例
数字
1 bit_length 返回表示该数字的时占用的最少位数 2 num = 31 3 result = num.bit_length() 4 print (result) 5 6 conjugate 返回该复数的共轭复数 7 num = 23.5 8 result = num.conjugate() 9 print (result) 10 11 _abs__ 返回绝对值 12 num = -23.5 13 result = num.__abs__() 14 print (result) 15 16 __add__ 两个数相加,相当于+ 17 num = -23.5 18 result = num.__add__(25) 19 print (result) 20 21 __divmod__ 相除,得到商和余数组成的元组 22 num = 24 23 result = num.__divmod__(6) 24 print (result) 25 26 27 __float__ 转换为浮点类型 28 num = 24 29 result = num.__float__() 30 print (result) 31 32 __floordiv__ 整除 33 num = 24 34 result = num.__floordiv__(-4) 35 print (result) 36 37 __getnewargs__ 内部调用 __new__方法或创建对象时传入参数使用 38 num = 78 39 result = num.__getnewargs__() 40 print (result) 41 (78,) 42 43 __hash__ 如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。在字典查找中,哈希值用于快速比较字典的键。两个数值如果相等,则哈希值也相等。 44 num = 784 45 result = num.__hash__() 46 print (result) 47 48 __index__ 49 用于切片,数字无意义 50 x[y:z] <= = > x[y.__index__():z.__index__()] 51 num = 784 52 result = num.__index__() 53 print (result) 54 55 __init__ 构造方法,执行 x = 123 或 x = int(10) 时,自动调用,暂时忽略 56 num = 784 57 result = num.__init__() 58 print (result) 59 60 __int__ 转换为整数 61 num = 784.21 62 result = num.__int__() 63 print (result) 64 65 __long__ 取余 66 x.__mod__(y) <==> x%y 67 num = 784 68 result = num.__mod__(781) 69 print (result) 70 71 __mul__ 相乘 72 num = 2 73 result = num.__mul__(3) 74 print (result) 75 76 __neg__ 取反 77 num = -12 78 result = num.__neg__() 79 print (result) 80 81 __or__ x|y 82 num = 12 83 result = num.__or__(7) 84 print (result) 85 print(12|3) 86 87 88 __pos__ x.__pos__() <==> +x 89 num = 1000 90 result = num.__pos__() 91 print (result) 92 93 94 __pow__ 幂 95 num = 1000 96 result = num.__pow__(2) 97 print (result) 98 99 __radd__ 加法 100 num = 1000 101 result = num.__radd__(2) 102 print (result) 103 104 __rand__ y&x 105 num = 1000 106 result = num.__rand__(100) 107 print (result) 108 109 __rdivmod__ 相除,得到余数和商,相当于divmod从右往左 110 num = 1000 111 result = num.__rdivmod__(100) 112 print (result) 113 114 __repr__ 转化为解释器可读取的形式 115 num = 1000 116 result = num.__repr__() 117 print (result) 118 119 __str__ 转换为人阅读的形式,如果没有适于人阅读的解释形式的话,则返回解释器课阅读的形式 120 num = 1000 121 result = num.__str__() 122 print (result) 123 print (type(result)) 124 <class 'str'> 125 126 127 __rfloordiv__ __rfloordiv__(500)500为除数 128 num = 2 129 result = num.__rfloordiv__(500) 130 print (result) 131 132 __rlshift__ num的平方*result 133 num = 4 134 result = num.__rlshift__(5) 135 print (result) 136 137 __rmod__ result%num 取余,类似mod 138 num = 7 139 result = num.__rmod__(6) 140 print (result) 141 142 __rmul__ 乘法 143 num = 7 144 result = num.__rmul__(9) 145 print (result) 146 147 __ror__ num|result 148 num = 7 149 result = num.__ror__(9) 150 print (result) 151 152 __rpow__ result**num 类pow 153 num = 3 154 result = num.__rpow__(2) 155 print (result) 156 157 __rrshift__ result二进制整体向右移num位 158 1011010 159 0001011 160 num = 3 161 result = num.__rrshift__(90) 162 print (result) 163 164 __rshift__ num二进制整体向右移result位 165 num = 90 166 result = num.__rshift__(3) 167 print (result) 168 169 __rsub__ result-num 减法 170 num = 90 171 result = num.__rsub__(3) 172 print (result) 173 174 __rtruediv__ result/num 得出的是浮点数 175 num = 90 176 result = num.__rtruediv__(180) 177 print (type(result)) 178 <class 'float'> 179 print (result) 180 181 __rxor__ 异或 182 num = 90 183 result = num.__rxor__(3) 184 print (result) 185 186 __sub__ num-result 187 num = 90 188 result = num.__sub__(2) 189 print (result) 190 191 __truediv__ num/result 取浮点 192 num = 90 193 result = num.__truediv__(2) 194 print (result) 195 196 __trunc__ 返回数值被截取为整形的值,在整形中无意义 197 num = 90.01 198 result = num.__trunc__() 199 print (result) 200 201 __xor__ 异或 同为0异为1 202 1011010 203 0000011 204 1011001 205 num = 90 206 result = num.__xor__(3) 207 print (result)