def shoot(self, limb):
if not limb:
pass
else:
limb = False
print Joe.body.head #prints out true
Bob.gun.shoot(Joe.body.head) # should print out false
print Joe.body.head #prints out true (???)
Run Code Online (Sandbox Code Playgroud)
我是Python新手,正在制作一款游戏作为LPTHW的一部分.我的拍摄功能应该通过将其设置为false来禁用肢体,但它根本不会编辑布尔值.考虑到我可以直接设置布尔值,这似乎有点多余,但是射击函数将计算的不仅仅是更改布尔值.非常感谢帮助.
为什么浮动首选精度?难道不是很大的整数来表示浮动给出的精度并且在所有机器上都是确定性的吗?例如,以浮点移动0.48124米的物体可以由以int或long移动48124微米的物体代表.
我已经安装了自己创建的自定义模块用于学习.如果我做
from my_first_module import test
test.thisprintssomething()
Run Code Online (Sandbox Code Playgroud)
该功能将起作用,但如果我这样做
import my_first_module
test.thisprintssomething()
Run Code Online (Sandbox Code Playgroud)
Python吐出,NameError:名称'test'未定义.如何在不使用"from"的情况下导入?
编辑:
我自己修好了.我忘了在my_first_module模块中的init .py中添加一个"import test"行.