Python Basics

In the following examples we'll be using a couple of programming things which are simple enough that, should you not be familiar with them, you might be able to figure out from the context. While the experienced programmers will tap their feet impatiently for this to finish, and the newbies are struggling to pick their dicts from their strings: a very short overview of the stuff you're missing.

Conditional statements: if a condition is met: execute a specific block of your script.

if1+1 == 2:print"still true"else:print"oops"

stilltrue

Compound statements: for each item in this list: execute a seperate block of your script.

foritemin [1, 2, 3, "a"]:printitem

123"a"

Assignment: this is basically setting something to a new value, or attaching a name to something.

a = 10printa

10

The information that you want to work with in programming comes in different forms and colors: text, numbers, sequences of things. Python offers a nice range of tupperware boxes to stick them in. More things to keep track of, but: useful and these will be your friends.

strings: text, letters, words, are called strings and they live between quotes. In order to allow quotes in strings you have several quote alternatives:

numbers: whole numbers, decimal numbers. You don't need to do anything special to make them, just write them.

# examples of numbersa = 1900b = -239345c = 1.349683d = 0

lists: sequences can be written between brackets. You've seen one earlier. Lists are powerful things to keep stuff in order. Some objects can behave like lists. List objects have useful methods to manipulate them.

dictionaries: these are similar to lists, but rather than just store a sequence, a dictionary stores a key: value pair. In order to get the value, you need to provide the key. Dictionaries are written between {braces}. Some objects can behave like dictionaries. Dictionary objects have useful methods to manipulate them. While lists have their sequencential order, dictionaries don't, something to remember when you're iterating.