class Number: def __init__(self, v): self.value = v def set(self, v): self.value = v def get(self): return self.value def __str__(self): return str(self.value) class NotSafeBit(Number): def bit_and(self, other_bit): if self.value == 1 and other_bit.get() == 1: return 1 else: return 0 class Bit(NotSafeBit): def __init__(self, v): self.value = 0 if v != 0: self.value = 1 def set(self, v): if v == 0: self.value = 0 else: self.value = 1 def different_types(): num = Number(10) nsBits = [] nsBits.append(NotSafeBit(10)) nsBits.append(NotSafeBit(1)) bits = [] bits.append(Bit(10)) bits.append(Bit(1)) print "Num: " + str(num) print "nsBits: " + str(nsBits[0]) + ", " + str(nsBits[1]) print "bits: " + str(bits[0]) + ", " + str(bits[1]) print "ns AND: " + str(nsBits[0].bit_and(nsBits[1])) print "bit AND: " + str(bits[0].bit_and(nsBits[1]))