【发布时间】:2015-10-10 01:45:00
【问题描述】:
如何使以下内容保持不变和真实? (换句话说,全局变量?)
UP :: Direction
DOWN :: Direction
LEFT :: Direction
RIGHT :: Direction
dirs = [UP, DOWN, LEFT, RIGHT]
我的尝试:
#global definitions
UP = True
DOWN = True
LEFT = True
RIGHT = True
dirs = [UP, DOWN, LEFT, RIGHT]
【问题讨论】:
-
这有什么问题?只是永远不要重新分配它们。
-
"constant and true" 不一定与 "globals" 相同 - 你可以(但通常不应该)拥有 global变量,并且绝对可以具有局部“常量”。但是,Python 并没有真正的常量,所有名称都可以重新分配。你到底想做什么?
标签: python boolean constants global definition