[‘abs’, ‘add’, ‘and’, ‘bool’, ‘ceil’, ‘class’,
‘delattr’, ‘dir’, ‘divmod’, ‘doc’, ‘eq’,
‘float’, ‘floor’, ‘floordiv’, ‘format’, ‘ge’,
‘getattribute’, ‘getnewargs’, ‘gt’, ‘hash’,
‘index’, ‘init’, ‘init_subclass’, ‘int’, ‘invert’,
‘le’, ‘lshift’, ‘lt’, ‘mod’, ‘mul’, ‘ne’,
‘neg’, ‘new’, ‘or’, ‘pos’, ‘pow’, ‘radd’,
‘rand’, ‘rdivmod’, ‘reduce’, ‘reduce_ex’, ‘repr’,
‘rfloordiv’, ‘rlshift’, ‘rmod’, ‘rmul’, ‘ror’,
‘round’, ‘rpow’, ‘rrshift’, ‘rshift’, ‘rsub’,
‘rtruediv’, ‘rxor’, ‘setattr’, ‘sizeof’, ‘str’,
‘sub’, ‘subclasshook’, ‘truediv’, ‘trunc’, ‘xor’,
‘bit_length’, ‘conjugate’, ‘denominator’, ‘from_bytes’, ‘imag’,
b = dir(int)
print(b)
[‘abs’, ‘add’, ‘and’, ‘bool’, ‘ceil’, ‘class’,
‘delattr’, ‘dir’, ‘divmod’, ‘doc’, ‘eq’,
‘float’, ‘floor’, ‘floordiv’, ‘format’, ‘ge’,
‘getattribute’, ‘getnewargs’, ‘gt’, ‘hash’,
‘index’, ‘init’, ‘init_subclass’, ‘int’, ‘invert’,
‘le’, ‘lshift’, ‘lt’, ‘mod’, ‘mul’, ‘ne’,
‘neg’, ‘new’, ‘or’, ‘pos’, ‘pow’, ‘radd’,
‘rand’, ‘rdivmod’, ‘reduce’, ‘reduce_ex’, ‘repr’,
‘rfloordiv’, ‘rlshift’, ‘rmod’, ‘rmul’, ‘ror’,
‘round’, ‘rpow’, ‘rrshift’, ‘rshift’, ‘rsub’,
‘rtruediv’, ‘rxor’, ‘setattr’, ‘sizeof’, ‘str’,
‘sub’, ‘subclasshook’, ‘truediv’, ‘trunc’, ‘xor’,
‘bit_length’, ‘conjugate’, ‘denominator’, ‘from_bytes’, ‘imag’,
‘numerator’, ‘real’, ‘to_bytes’]
[‘abs’, ‘add’, ‘and’, ‘bool’, ‘ceil’, ‘class’, ‘delattr’, ‘dir’, ‘divmod’, ‘doc’, ‘eq’, ‘float’, ‘floor’, ‘floordiv’, ‘format’, ‘ge’, ‘getattribute’, ‘getnewargs’, ‘gt’, ‘hash’, ‘index’, ‘init’, ‘init_subclass’, ‘int’, ‘invert’, ‘le’, ‘lshift’, ‘lt’, ‘mod’, ‘mul’, ‘ne’, ‘neg’, ‘new’, ‘or’, ‘pos’, ‘pow’, ‘radd’, ‘rand’, ‘rdivmod’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘rfloordiv’, ‘rlshift’, ‘rmod’, ‘rmul’, ‘ror’, ‘round’, ‘rpow’, ‘rrshift’, ‘rshift’, ‘rsub’, ‘rtruediv’, ‘rxor’, ‘setattr’, ‘sizeof’, ‘str’, ‘sub’, ‘subclasshook’, ‘truediv’, ‘trunc’, ‘xor’, ‘bit_length’, ‘conjugate’, ‘denominator’, ‘from_bytes’, ‘imag’, ‘numerator’, ‘real’, ‘to_bytes’]
3. 利用位运算实现快速计算
通过 <<,>> 快速计算2的倍数问题。
n << 1 -> 计算 n2
n >> 1 -> 计算 n/2,负奇数的运算不可用
n << m -> 计算 n(2^m),即乘以 2 的 m 次方
n >> m -> 计算 n/(2^m),即除以 2 的 m 次方
1 << n -> 2^n
通过 ^ 快速交换两个整数。 通过 ^ 快速交换两个整数。
a ^= b
b ^= a
a ^= b
通过 a & (-a) 快速获取a的最后为 1 位置的整数。
00 00 01 01 -> 5
&
11 11 10 11 -> -5
00 00 00 01 -> 1
00 00 11 10 -> 14
&
11 11 00 10 -> -14
00 00 00 10 -> 2
体会:仍然不太懂的Pathon的生涩知识点,面对难懂的,可以向群里的大哥哥,大姐姐,请教,一个萌新进化为老手!