索引清單項目
清單中的每個項目都有對應的索引值。記得 Python 採用從 0 開始的索引,因此清單的第一個元素位在索引 0。本練習要讓你練習從清單中擷取單一元素。
工作環境裡已提供公司名稱與股價的清單 names 與 prices。
本練習屬於課程
Python 金融入門
練習說明
- 印出
names的第一個元素。 - 印出
names的第二個元素。 - 使用負索引,印出
prices的最後一個元素。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the first item in names
print(____)
# Print the second item in names
print(____)
# Print the last element in prices
print(____)