[英]python how to judge whether a variable is boolean type
In python, how to judge whether a variable is bool type,python 3.6 using 在python中,如何判断变量是否为bool类型,python 3.6使用
for i in range(len(data)):
for k in data[i].keys():
if type(data[i][k]) is types.BooleanType:
data[i][k] = str(data[i][k])
row.append(data[i][k])
#row.append(str(data[i][k]).encode('utf-8'))
writer.writerow(row)
row = []
but it errors: 但它错误:
if type(data[i][k]) is types.BooleanType:
TypeError: 'str' object is not callable
you can check type properly with isinstance()
你可以用isinstance()
正确检查类型
isinstance(data[i][k], bool)
will return true
if data[i][k]
is a bool 如果data[i][k]
是bool,则返回true
isinstance(data[i][k], bool) #returns True if boolean
代替 :
if type(data[i][k]) is types.BooleanType:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.