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)))
基本上想要检查天,月和年是否是一个int,我能做的最紧凑的方法是上面但是我不确定它是最好的但是我相信它会比每个if语句更好中间体
答案 0 :(得分:12)
您可以使用all
和generator expression:
if not all(isinstance(i, int) for i in [days, months, years]):
答案 1 :(得分:3)
if not all(isinstance(i, int) for i in [days, months, years])