開始使用免費開始

索引清單項目

清單中的每個項目都有對應的索引值。記得 Python 採用從 0 開始的索引,因此清單的第一個元素位在索引 0。本練習要讓你練習從清單中擷取單一元素。

工作環境裡已提供公司名稱與股價的清單 namesprices

本練習屬於課程

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(____)
編輯並執行程式碼