>>> format(8, 'b') # 二进制
'1000'
>>> format(1/3, '.2%') # %百分比
'33.33%'
如果类没有定义 __format__ 方法,从 object...继承的方法会返回 str(my_object),调用 __str__()
print(format(v1)) # (315687.0, 4.0)
print(format(v1, '.3f')) #...__x = 100 # 值不可以变更
print(v1) # (315687.0, 4.0)
# v1.x = 100 # AttributeError: can't set attribute
添加...hash(v3)) # 30
print(set([v1, v2, v3])) # {Vector2D(315687.0,4.0), Vector2D(10.0,20.0)}
3....覆盖类属性
print(v1.typecode) # d
print(v2.typecode) # d
print(bytes(v1)) # b'd\x00\x00\x00\x00\x00\x00Y