python - 为什么 if 语句正在执行但条件为假?
问题描述
即使变量bullets_fire
包含 boolean False
,下面的命令也会被执行。我还为嵌套在 if 语句中的 bullets_fire 添加了 print 语句,它输出False,为什么要执行它呢?
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and not bullets_fire:
print(bullets_fire)
bullets_fire = True
bullets_x = player_x
bullets_y = player_y
解决方案
您的条件包含not
在布尔变量之前。仅当event.key == pygame.K_SPACE
评估为True
和bullets_fire
评估为时才会执行False
,因为not False
与 相同True
。
推荐阅读
- ios - Xamarin 在 iOS 中形成图像大小
- c# - 如何将 PictureBox 变成具有“移动功能”的类并从 Form.cs 中调用?
- regex - sed 用于替换的反向引用
- powershell - PowerShell Export-Csv 命令中的控制台文本
- excel - 对 REN 方法的困惑
- api - Symfony 4 + JMS 序列化程序 - 内部服务器错误
- node.js - 将输入发送到通过标准输入接受输入的程序
- android - Android Studio 运行完整 [assemble] 而不是特定配置
- javascript - 在 document.on 函数中获取事件的当前目标
- sql - 使用 ExecuteSQL 或其他处理器在 Nifi 中调用 SQL 函数