位运算
# !/usr/bin/python3# -*- coding: utf-8 -*-
# @Time : 2023/2/18 22:35
# @Author : xiongming
# @File : weiyunsuan.py
# @Desc : 位运算
# 且&
print(3 & 4)
print(3 & 2)
print(bin(2))
print(bin(3))
print(bin(4))
# 或 |
print(3 | 2)
print(3 | 4)
# 取反 ~
print(~2)
print(~3)
print(~4)
# 异或 ^ 不同值时取1
print(3 ^ 2)
print(3 ^ 4)
# 移位 右移除2的指数,左移扩大2的指数
print(bin(8))
print(8 >> 2)
print(8 >> 3)
print(8 << 2)
print(8 << 3)
# 地板除
print(8 // pow(2, 2))
print(8 // pow(2, 3))
print(8 * pow(2, 2))
print(8 * pow(2, 3))
import math
# 0.2 + 0.1 /= 0.3 False ulp() 函数
print(0.2 + 0.1 == 0.3 + math.ulp(0.3))
class C:
def __index__(self):
print("被拦截了")
return 3
c = C()
s = "FishC"
a = s
b = bin(c)
print(a)
print(b)
页:
[1]