小编Sma*_*own的帖子

如何在Python中强制属性为int?

我有以下课程:

class C3DPoint(object):
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

    # Other methods
Run Code Online (Sandbox Code Playgroud)

我想确保如果有人设置v3dpoint.x = <sth>它会在 vale 不是字符串的情况下抛出错误。

如何才能做到这一点?

python oop

2
推荐指数
1
解决办法
1613
查看次数

标签 统计

oop ×1

python ×1