想知道是否有办法将布尔值从true / false更改为in / out?
我的下面的代码是一个布尔开关,但我想让它打印或打印不是0或1
while True:
Tag = raw_input("Please Scan your Tag: ")
q = "SELECT * FROM CARDS WHERE TAG=?"
up = "UPDATE CARDS SET FLAG = (CASE WHEN FLAG=0 THEN 1 ELSE 0 END) WHERE TAG=?"
cursor.execute(q, (Tag,))
cursor.execute(up, (Tag,))
conn.commit()
for row in cursor:
print row [1] + " has been checked " + row[3]
答案 0 :(得分:3)
您可以使用'in' if condition else 'out'
:
print row [1] + " has been checked " + ('in' if row[3] else 'out')
答案 1 :(得分:0)
而不是:
print row [1] + " has been checked " + row[3]
尝试:
print row [1] + " has been checked " + ("in" if row[3] else "out")