開始使用免費開始

更新變數

你已經把義大利麵食譜的初始數值存起來,但現在發現需要做些調整。你比較喜歡「fusilli」而不是 spaghetti,而且決定多用一點麵。在 Python 中,你可以像一開始建立變數時一樣,將變數重新指派為新值來輕鬆更新。

來練習更新食譜的變數,並把新值印出來確認變更。

本練習屬於課程

Python 入門(開發者向)

檢視課程

練習說明

  • pasta_type 變數更新為字串 "fusilli",取代目前的值。
  • quantity 變數更新為整數 100

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

print(pasta_type)
print(quantity)

# Update the pasta type to fusilli
pasta_type = ____

# Update the quantity to 100
quantity = ____

print(pasta_type)
print(quantity)
編輯並執行程式碼