gpt4 book ai didi

python - 重命名 true false boolean 值

转载 作者:行者123 更新时间:2023-11-30 23:09:51 24 4
gpt4 key购买 nike

想知道是否有办法将 boolean 值从 true/false 更改为 in/out?

我下面的代码是一个 boolean 开关,但我希望它打印或输出不是 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]

最佳答案

您可以使用'in' if condition else 'out':

print row [1] + " has been checked " + ('in' if row[3] else 'out')

关于python - 重命名 true false boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30953640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com