コード例 #1
0
from vector_v7 import Vector
from vector2d_v3 import Vector2d

v1 = Vector([3, 4, 5])
v1 + (10, 20, 30)

v2d = Vector2d(1, 2)
v1 + v2d
コード例 #2
0
from vector2d_v3 import Vector2d

v1 = Vector2d(3, 4)
print(v1.__dict__)
print(v1._Vector2d__x)

v1._Vector2d__x = 123
v1._Vector2d__y = 321

print(v1.x, v1.y)
print(v1)
"""
私有属性:以 __mood 形式, 即以两个前导下划线,尾部没有或最多一个下划线,以这种形式定义的属性

“受保护的”属性: 使用一个下划线前缀的属性

但是实质上,无论“私有属性”或者“受保护的属性”, 都是加引号的,因为并不能真正的实现私有和不可变。

"""
コード例 #3
0
from vector2d_v3 import Vector2d

v1 = Vector2d(1.1, 2.2)
dumped = bytes(v1)
print(dumped)
print(len(dumped))
v1.typecode = 'f'
dumpf = bytes(v1)
print(dumpf)
print(len(dumpf))
print(v1.typecode, Vector2d.typecode)
コード例 #4
0
    print(f"{-v1=}")
    print(f"{-v1}")
    print(f"{+v1=}")
    print(f"{+v1}")
    # print(f"{~v1=}")

    v1 = Vector([1, 2, 3])
    v2 = Vector((10.1, 20.1))
    v3 = v1 + v2

    print(f"{v1}")
    print(f"{v2}")
    print(f"{v3}")

    v4 = (1, 2, 3) + v1

    print(f"{v4}")

    from vector2d_v3 import Vector2d

    v5 = Vector2d(1, 2) + v1

    print(f"{v5}")

    # v6 = v1 + 1
    #
    # print(f"v6 = {v6}")

    v7 = v1 + 'ABC'

    print(f"v7 = {v7}")