Suppose we have in Python 3.x (and I guess in Python 2.6 and in Python 2.7 too) the following functions:
>>> def dbl_a(p): return p*2
>>> def dbl_b(p): return(p*2)
>>> def dbl_c(p): return (p*2)
If we run them we get:
>>> dbl_a(42)
84
>>> dbl_b(42)
84
>>> dbl_c(42)
84
The three functions provide the same result (value and type) and they seem to be equivalent.
But which of them has the more correct return
statement?
Is there any side-effect in any of those definitions?
The same questions apply to the following situation with multiple values returned:
>>> def dbl_triple_a(p): return p*2, p*3
>>> def dbl_triple_b(p): return(p*2, p*3)
>>> def dbl_triple_c(p): return (p*2, p*3)
>>> dbl_triple_a(42)
(84, 126)
>>> dbl_triple_b(42)
(84, 126)
>>> dbl_triple_c(42)
(84, 126)
In this case every function returns a tuple, but my questions still remain the same.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…