Crash Course: Python



Welcome to one of our Crash Course series! In this post, we will cover Python. This course is meant for coders who have already learned a programming language, but feel free to try if you are up for the challenge.

The idea here is there are some items common to almost every language:

  • Variables
  • Basic Data Type - string, number, list, dictionary
  • Operators
  • Control Flow - if/else
  • Loops
  • Functions

You could also argue classes, but there are many functional-first programming languages, so we will keep with this list. After this list, you start to get into more specific language features, like list comprehensions in Python, as well as more intermediate and advanced features like the standard library and concurrency.

We will briefly cover each of the above topics before using Python. Let's get started!

Hello World

Let's start with the simple hello world script. We will introduce the print function which is common to many languages.

print("Hello World")


In python, we can declare variables using the = assignment operator. You do not need to specify a type.

name = "Keith"

Data Types

Okay, not to get so more details going. Let's briefly look at each of the basic data type in python. You should have seen many of these in your previous language.

## Strings
test = "Hello, Everoyne!"

## Numbers
age = 18

amount = 12.9


Arrays are called lists in python. You can also have multiple types in a list.

## Creating
todo = ["step1", "step2"]
mixedList = [1, 2, "one", "two"]

## Acess/reading

## Updating
mixedList[1] = "a new item"

## Deleting
del todo[1]

## Helpful functions

combined = todo + mixedList

repeated = [4] * 12


Maps, Hashmaps, etc are called Dictionaries in Python. They work and much the same way as other languages. You can also use multiple lines without following normal indention rules.

Notice that you need to use quotes on the key and value for Python Dictionaries.

## Creating
profile = {
  'name': 'Keith',
  'Age': 18,

## Accessing

## Updating
profile['Age'] = 21

## Deleting
del prfile['Name']


The basic operators are the same in Python as most languages. Let's take a review of the most common.

first = 10
second = 2

## Math
print(first + second)
print(first - second)
print(first * second)
print(first / second)

## Comparisons

# equal to
print(first == second)

# no equal
print(first != second)

# greater than
print(first > second)

# greater than or equal
print(first >= second)

# less than
print(first < second)

# less than or equal
print(first <= second)

Control Flow - if/else

For Python, there are no curly brackets. Python relies on indentation for blocks and nesting. Let's see how this works for conditional flows (if, else if, and else).

age = 20

if age > 60:
  print("You are to old!")
elif age < 5:
  print("You are to young!")
  print("Just right")

Notice that we don't need parenthesis either. We the format is if [condition]:.


Python has both a for and while loop. One special keuword in Python is the in keyword, which let's you use generators. This is very helpful when iteratoring of lists, but has many other advantages.

count = 0
while count < 10:
  count += 1

todoList = ["one", "two", "three"]
for item in todoList:


To create functions in Python, we use the def keyword followed by the name of the function, parenthesis and the arguments needed.

def getFullName(firstName, lastName):
  return firstName + " " + lastName

full = getFullName("Keith", "Holliday")
GoTea - KoalaTea