Jump to content

PyGame Guide/Python Crash Course

From Wikibooks, open books for an open world

A basic program

[edit | edit source]

A simple Hello World program:


print("Hello World")

Variables

[edit | edit source]

Variables in Python are dynamically typed. This means that a variable may hold either a number, string, or any object.

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

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

Input and output

[edit | edit source]

If statements

[edit | edit source]
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 loops

[edit | edit source]

For loops

[edit | edit source]

Functions

[edit | edit source]

Classes

[edit | edit source]

Inheritance

[edit | edit source]