Python

Python is a general purpose scripting language created in 1991 by Guido van Rossum. It's design philosophy emphasizes code readability and simplicity while still being powerful. Python has been a fairly popular scripting language for gamedev, but not to the extent that Lua has.

Pros and Cons

Pros

  • Beginner friendly
  • Clean syntax
  • Active community
  • No variable declaration
  • Multi-paradigm
  • Dynamically-typed
  • Portable - runs on all major operating systems

Cons

  • No switch-statements
  • No support for anonymous functions (lambda being the only exception)
  • The relation between modules and files can be very confusing - when importing modules you don't put the file name as a string and you don't include a file extension
  • Slow even compared to other scripting languages like Lua
  • Python's use of white-spacing can make code unreadable on different operating systems

Python 2 vs 3

There are currently two versions of Python being supported: Python 2.x and Python 3.x (though Python 2.x is planned to be discontinued by 2020). The reason for this is due to compatibility issues with the two. For example, in Python 3, many of Python 2's statements like print were replace with functions. Due to this many Python 2 libraries are partially compatible or not compatible at all with Python 3. However, Python 3.x has a feature to convert Python 2 scripts to Python 3 and many libraries are adding support to Python 3, but this is still an issue worth pointing out.

Supported tools

Frameworks

Engines

Resources

Tutorials

Online Python Coding/Compile

  • CodePad.org - Also acts as a pastebin and a simple collaboration tool

Libraries

  • Numpy - A collection of scientific computing modules
  • EasyGUI - A very simple GUI module that uses functional programming to create simple dialogue boxes
  • Py2Exe - Converts Python scripts to Windows executables
  • cx_Freeze - Like Py2Exe except it's cross-platform

Sample Code

Hello World

#prints to stdout, will only run once the command is executed
print("Hello, world!")
 
#for a hello world function, which prints when it is called:
def helloworld():
    print("Hello, world!")
#note the indent

FizzBuzz

#prints "fizz" every 3, and "buzz" every 5
def fizzbuzz(counter):
    output = str(counter) + " "
    #counter is an int, must be cast to a string
    if counter % 3 is 0:
        output += "fizz"
    if counter % 5 is 0:
        output += "buzz"
    print(output)
#now run fizzbuzz() in a loop in our main function
def main():
    for x in range(16):
        fizzbuzz(x)
#the main function won't run unless you call it
#a common solution is to use something like this
if __name__ == "__main__":
    main()
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License