小编ill*_*ian的帖子

有没有更好的方法来检查多个变量是Python中的单一类型?

    if not [True]*3 == [isinstance(i, int) for i in [days, months, years]]:
        raise TypeError('days, months, and years must be int type not %s %s %s'
                        % (type(days), type(months), type(years)))
Run Code Online (Sandbox Code Playgroud)

基本上想要检查天,月和年是否是一个int,我能解决的最紧凑的方法是上面但是我不确定它是最好的但我相信它会比每个int的多个if语句更好.

python comparison types exception

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

标签 统计

comparison ×1

exception ×1

python ×1

types ×1