Think Python,第二版,作者將條件表達式定義爲」根據條件,具有兩個值之一的表達式「。但是我反映了它之後,我一直認爲定義的準確性可能是值得懷疑。下面是其使用條件表達式編寫的函數: def get_sign(n):
"""Returns 1 if n is a positive number, -1 if n is a negative number,
or 0 if n
它是否會阻止問題在重新定義條件的所有可能分支之前定義變量? 例如應此代碼: # Condition could fail
try:
textureIndices = someExpression()
# textureIndices is defined here if it does
except:
textureIndices = []