擅长:python、mysql、java
<p>查看代码,使用位置/位置变量,还可以将X、Y和Z位置统一为一个公共类型,例如使用命名元组:</p>
<pre><code>from collections import namedtuple
Position = namedtuple("Position", "x, y, z")
locations = {
"chair": Position(1, 2, 5.3),
"table": Position(5, 3.732, 6),
"lamp": Position(4.4, 7.2, 2)
}
print "Chair X location: ", locations["chair"].x
</code></pre>
<p>不过,只是个建议。</p>