Fundamentals of Python
Timo Reusch

This document summarizes the most important programming concepts in python. Main ressource was the W3Schools Python tutorial, which can be found here: https://www.w3schools.com/python/


 

Variables

General

 

Data types

Data typeExample
strx = "Hello World"
intx = 20
floatx = 20.5
complexx = 2j (jist der Imaginärteil)
boolx = True (true does not work!)
bytesx = b"Hello"

 

Strings

 

Operators

The standard ones and also

 

Conditional statements and loops

break and continue are supported.

 

Data collections

Arrays are not supported btw.

Data TypeExampleParticularities
listx = ["apple","banana","cherry"]List items are ordered, changeable, and allow duplicate values.
List items are indexed, the first item has index [0], the second item has index [1] etc.
dictx = {"name" : "John", "age" : 36}Key-Value-Pairs, ordered (from v3.7 on)
setx = {"apple", "banana", "cherry"}

x = frozenset({"apple","banana","cherry"})
A set is a collection which is both unordered and unindexed. Set items are unordered, unchangeable, and do not allow duplicate values. But: Once a set is created, you cannot change its items, but you can add new items. To prevent this, you can use a frozenset
tuple("apple", "banana", "cherry")Tuple items are ordered, unchangeable, and allow duplicate values. Tuples are unchangeable. Can only be accessed with foreach.

Lists

 

Dicts

 

Functions

function definitions cannot be empty, but if you for some reason have a function definition with no content, put in the pass statement to avoid getting an error:

Object orientation

Additional

User Input

You can request user input using the input()-Method:

 

Working with files

You can return one line by using the readline() method:

Loop through the file line by line:

 

Testing

First, you must import unittest!