擅长:python、mysql、java
<p>在语言层面上,没有办法以某种方式将两个T变量“绑定”在一起,这样当另一个变量被更新时,其中一个变量就会自动更新,如果你这么想的话</p>
<p>正确的方法是指定一个“setter”函数,您可以调用该函数来更新强度,它还可以更新hp。
所以你可以吃点类似的东西</p>
<pre><code>def set_strength(new_strength):
return new_strength, 50 + (new_strength * 5)
strength, hp = set_strength(strength + skilladdnum)
</code></pre>
<p>但这有点难看,感觉不习惯。
一旦你进入了<a href="https://docs.python.org/3/tutorial/classes.html" rel="nofollow noreferrer">classes</a>和<a href="https://realpython.com/python3-object-oriented-programming/" rel="nofollow noreferrer">object oriented programming</a>,你就会有一个类<code>Character</code>,它会有字段(变量)<code>hp</code>和<code>strength</code>,在这个类的外部,你只会使用像<code>set_strength</code>这样的函数,在类<code>Character</code>内部,你会注意在所有地方正确地更新它们</p>