跳至內容

PyGame 指南/Python 速成課程

來自華夏公益教科書,開放書籍,開放世界

一個基本程式

[編輯 | 編輯原始碼]

一個簡單的 Hello World 程式


print("Hello World")

Python 中的變數是動態型別的。這意味著一個變數可以儲存數字、字串或任何物件。

variably = 40
variably = 40.9
variably = "fourty point nine"

print(variably)
# Based on the assignment above, this will print "fourty point nine"

輸入和輸出

[編輯 | 編輯原始碼]

If 語句

[編輯 | 編輯原始碼]
if True:
  print("This will always execute")

if 6 > 5:
  print("6 is, in fact, greater than 5")

variably = False
if variably:
  print("variably is True")
else:
  print("variably is False")

letter = "a"
if letter == "a":
  print("got option A")
elif letter == "b":
  print("got option B")
elif letter == "c":
  print("got option C")
else:
  print("got unknown option")

While 迴圈

[編輯 | 編輯原始碼]

For 迴圈

[編輯 | 編輯原始碼]
華夏公益教科書