[英]Can anyone help me understand a part of the code in this Triangle Class?
[英]Can anyone help me to understand this code
a=['apple','banana','cherry']
a[1],a[2]=a[2],a[1]
print(a)
Output:
['apple', 'cherry', 'banana']
試圖理解代碼。
a=['apple','banana','cherry']
a[1],a[2]=a[2],a[1]
print(a)
Output: ['apple', 'cherry', 'banana']
基本上,這個 python 代碼的作用是:
交換列表 a 的第二個和第三個元素,因為 python 中的列表索引從 0 開始。
您可以參考以下文章 - Python 列表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.