Python >>> a, b = b, a + b
>>> a , b = 0 , 1
>>> a
0
>>> b
1
>>> while b < 10:
print(b)
a , b = b , a + b
1
1
2
3
5
8
Is it the same as the following codes?
>>> a , b = 0 , 1
>>> a
0
>>> b
1
>>> while b < 10:
print(b)
a = b
b = a + b
1
2
4
8
The answer is "NO" because the expressions on the right hand side are evaluated before being assigned to the left hand side.
Thus it is equivalent to:
>>> a , b = 0 , 1
>>> a
0
>>> b
1
>>> while b < 10:
print(b)
c = a + b
a = b
b = c
1
1
2
3
5
8
[Reference]
https://docs.python.org/3/tutorial/introduction.html
http://stackoverflow.com/questions/21990883/python-a-b-b-a-b
文章標籤
全站熱搜

之的不會然文道果三那大這年來來年物月用理學, 115國語□言☉翻○譯﹎公司◇ 華碩﹍翻譯﹋社◎ 提供﹉佛蘭♀芒§文◎翻譯○等服♂務○ 電﹉話: 02-﹂2369-0937 LINE客服﹌ ID: t23690932 翻譯﹎社|〇0rz.tw/Nw6CO