跳至内容

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 循环

[编辑 | 编辑源代码]
华夏公益教科书