glossary#

==

Testing for equality TODO: example, link

all()

built in function. From the official Python documentation at https://docs.python.org/3/library/functions.html#all:

Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to:

def all(iterable):
for element in iterable:
    if not element:
        return False
return True
any()

built in function, is another way of chaining multiple expressions using the or keyword. TODO: link, example

.append()

a method of a list to append elements to the end of the list. See data structure. Python documentation: https://docs.python.org/3/tutorial/datastructures.html?highlight=append#more-on-lists

argument

see function. Argument is the parameter that is passed to a function when the function is called (at the function call)

assert

see https://docs.python.org/3/reference/simple_stmts.html?highlight=assert#the-assert-statement

await

from official Python documentation: Suspend the execution of coroutine on an awaitable object. Can only be used inside a coroutine function.

await_expr ::= “await” primary

New in version 3.5. TODO: links, example

bool

A boolean value that can either be True or False.

TODO: link to boolean operators

boolean value See bool

break

Python keyword to exit out of a for or while loop

built-in functions

See the official Python documentation https://docs.python.org/3/library/functions.html?highlight=enumerate#built-in-functions

  • A

    • abs()

    • aiter()

    • all()

    • any()

    • anext()

    • ascii()

  • B

    • bin()

    • bool()

    • breakpoint()

    • bytearray()

    • bytes()

  • C

    • callable()

    • chr()

    • classmethod()

    • compile()

    • complex()

  • D

    • delattr()

    • dict()

    • dir()

    • divmod()

  • E

    • enumerate()

    • eval()

    • exec()

  • F

    • filter()

    • float()

    • format()

    • frozenset()

  • G

    • getattr()

    • globals()

  • H

    • hasattr()

    • hash()

    • help()

    • hex()

  • I

    • id()

    • input()

    • int()

    • isinstance()

    • issubclass()

    • iter()

  • L

    • len()

    • list()

    • locals()

  • M

    • map()

    • max()

    • memoryview()

    • min()

  • N

    • next()

  • O

    • object()

    • oct()

    • open()

    • ord()

  • P

    • pow()

    • print()

    • property()

  • R

    • range()

    • repr()

    • reversed()

    • round()

  • S

    • set()

    • setattr()

    • slice()

    • sorted()

    • staticmethod()

    • str()

    • sum()

    • super()

  • T

    • tuple()

    • type()

  • V

    • vars()

  • Z

    • zip()

  • _

    • import()

case sensitive

means that a difference is made between lowercase and UPPERCASE. Python is a case sensitive language: The strings “camel” and “Camel” and “CameL” are three different strings for Python.

class

python keyword to start a class definition

continue

a command to force the program flow back to the start of a loop. See for and while. See also break.

data structure

Python has several data structures. Those data structures are built in:

  • tuple: comma-separated values in round brackets. immutable.

  • list: comma-separated values in square brackets. mutable.

  • dictionary: comma-separated key:value pairs in curly brackets. Key and value are separated by an colon. Keys must be unique.

  • set: comma-separated values in curly brackets. A set can not have duplicate values.

TODO: examples

def

Python keyword to start a function definition. See function

docstring

see https://docs.python.org/3/glossary.html#term-docstring

doctest

Special code inside of a docstring to test a function. See https://docs.python.org/3/library/doctest.html?highlight=doctest#module-doctest

dictionary

A dictionary is a data structure of comma separated key-value pairs, where the keys and the values are separated by an comma. Dictionaries are mutable and iterable. See also data structure.

Example:

# dictionary, keys is the product name, value is the price
pricedict = {
    "Coca Cola": 2.5,
    "Milk" :     1.33,
    "Wine":      2,
    }
# getting value if key is known:
print(pricedict["Milk"])  # output: 1.33
# iterating over the keys:
for product in pricedict:  
    print(product)
# output:
#Coca Cola
#Milk
#Wine

# changing a value
pricedict["Milk"] = 0.99
# adding a key:value pair:
pricedict["Beer"] = 1.80
# printing
print(pricedict)
# output: {"Coca Cola":2.5, "Milk":0.99, "Wine":2,"Beer":1.8 }
dictionary.keys()

the keys of a dictionary. Can be used for iterating over the keys using a for loop. Can be converted into a list using list()

dictionary.items()

the (key, value) tuples of a dictionary. Can be used for iterating over the (key,value) tuples using a for loop. Can be converted into a list of tuples using list()

dictionary.values()

the values of a dictionary. Can be used for iterating over the values using a for loop. Can be converted into a list using list()

enumerate()

enumerate takes an iterable (usually, a list or a string) and creates angenerator wielding the index each element and the each elemnt of the iterable. This is useful for example inside of a for loop:

name = "Alice"
for i, char in enumerate(name):
    print(i, char)
# output is:
#0 A
#1 l
#2 i
#3 c
#4 e

See official Python documentation https://docs.python.org/3/library/functions.html?highlight=enumerate#enumerate

endless loop

a loop constructed with an while True: line. This loop runs endless, until a break command allows the program flow to escape from the loop. See loop.

# example for endless loop
number = 1
while True:
    print(number)
    number += 1
# this loop will run endless (until the computer runs out of memory)
else

The else keyword is usually found inside of an if block. It can also be part of an for loop or of an while loop.

except

see try

exception

see official Python documentation https://docs.python.org/3/library/exceptions.html?highlight=exception TODO examples

f-string

fstrings are strings with an f prefix and some curly braces ({}) inside of the string. See https://docs.python.org/3/glossary.html#term-f-string. See also Format Specification Mini Language

False

Python keyword, indicating that something is not True.

finally

Python keyword, to use at the end of an tryexcept block. The indented code block after finally will be always executed.

float

data type for numbers with an decimal point. TODO: link, example

for

Python keyword to start a for loop. see loop. Python documentation: https://docs.python.org/3/tutorial/controlflow.html?highlight=loops#for-statements

Format Specification Mini Language

see the official Python documentation https://docs.python.org/3/library/string.html?highlight=format mini language#formatspec

function

see Python official documentation: https://docs.python.org/3/glossary.html#term-function

function call

the code line that is calling (and executing) the function (the function name is written with round parantheses) in contrast to the function definition where the function is only defined (using the def keyword) but not called.

function definition

the first line of a function is called the function definition. It must always start with the keyword def , followed by the function name and round brackets. Inside the round brackets can be (comma separated) parameters, each parameter can have an default value. The function definition must always end with a colon. TODO: example, link to pdf

generator

see official documentation: https://docs.python.org/3/glossary.html#index-19

immutable

Immutable means that something is not mutable

is

Python operator. Mostly to test if something is None

graphical user interface

Graphical User Interface. see user interface

GUI

Graphical User Interface. See user interface.

IDLE

Interactive Development Learning Enviroment. IDLE is the name of a code editor that is automatically installed together with Python. IDLE has an code editor mode (to write longer pieces of code) and an interactive mode (to try out single commands or short loops). IDLE starts in the interactive mode, a so called REPL or Python shell.

Code examples that are meant to be written inside of a Python shell start with a special prompt, the triple “greater sign”: >>>, and always show the output directly below the command. (The output has no prompt). Example:

1>>>"hello world".upper()
2"HELLO WORLD"
if

if is a Python keyword and can be part of an complex structure: if , if ... else, if ... elif..., if ... elif ...else. See the official Python documenation at https://docs.python.org/3/reference/compound_stmts.html#the-if-statement

TODO: examples

import

import is a Python keyword. Generally located at the top of a Python program, you must import Python modules before you can use them.

immutable:

From the Python documentation https://docs.python.org/3/glossary.html#term-immutable:

An object with a fixed value. Immutable objects include numbers, strings and tuples. Such an object cannot be altered. A new object has to be created if a different value has to be stored. They play an important role in places where a constant hash value is needed, for example as a key in a dictionary.

in

python operator. Can test if an element is in another sequence. For example: "a" in "abc" equals True

input()

input() is a function that waits for the user to type something in the keyboard and hit the ENTER key.

# what the user types will be saved i
# in the variable `username`:
username = input("type your name: ")
print("Hello", username)
int()

built-in Python function to convert another type (like string or float) into an integer. If the conversion does not work, python raises an ValueError

Examples:

my_string = "888"
my_integer  =int(my_string) # works
print(my_integer +1 )
# output is: 889
bad_string = "seven"
print(int(bad_string))
# output is: ValueError: invalid literal for int() with base 10: 'seven'
integer

data type for whole numbers TODO link

iterable

if a datastructre can be iterated over (in a for loop), it is iterable.

iterate

To iterate over an iterable means to use a for loop to process each item of an iterabel. Example: iterating over the items in a list:

1for name in ["my", "little", "garden"]:
2    print(name)
3# 
4
keyword

Python has several →keywords, you best memorize them:

Python keywords#

False

await

else

import

pass

None

break

except

in

raise

True

class

finally

is

return

and

continue

for

lambda

try

as

def

from

nonlocal

while

assert

del

global

not

with

async

elif

if

or

yield

len()

built in function to find out how many elemnts a data structure has. TODO: link, example

list

see data structure

list()

built in function to convert something (like a string or a tuple etc.) into a list.

list.append()

a method of a list to append one element to the end of the list.

names = [] # empty list
names.append("Alice")
names.append("Bob")
print(names)
# output is: ["Alice","Bob"]
list.copy()

to create a copy of a list, either use the .copy() method of lists or write a colon in square brackets:

original_list = ["Alice", "Bob", "Carl"]
copy_of_list =  original_list[:]
# is the same as:
# copy_of_list = original_list.copy()
list.count()

a method of list. It counts how often an element is inside the list. Example:

my_list = ["Alice","Bob","Carl","Alice"]
print(my_list.count("Alice"))
# output is: 2
list comprehension

Iteration over a list to create a new list. TODO: example

loop

A code block that is repeated several times is called a “loop”. In Python, a loop can be constructed by using a for in loop or by using a while loop. The for loop runs a defined number of times, the while loops runs as long as a epression remains True.

Loops can be escaped using the break command and the program flow can be forced go back to the start to of the loop using the continue command.

A little known fact is that loops can also have an else block after the loop: The code block in this else block will only be executed if the loop was “running through”… not escaped by an break command.

A loop starting with an while True: command is called an endless loop.

TODO: examples

mutable

if a data structure allows the changing of its elements (adding, removing, replacing) it is mutable. Examples: list, dictionary, set. see data structure.

None

A python keyword, indicating “Nothing” or “empty”. Do not confuse with the value Zero (0).

or

Python keyword for boolean logic. Also see any(). TODO: link, examples

parameter

A parameter is the name of a variable that can be passed to a function as an argument. See function.

pass

A python command that does literally nothing, but enables an idented block to have a valid command. See official documentation: https://docs.python.org/3/reference/simple_stmts.html?highlight=pass#grammar-token-python-grammar-pass_stmt

PEP

PEP stands for Python Enhancement Proposal. Before a feature is implemented into a new version of Python, it is summarized in a PEP and then discussed.

PEP8

(See PEP. A Python style guide that is followed by most Python programmers. While the programming language Python is very tolerant about the writing style, the style guide is more strict and it is good practice to follow the recommendations of the style guide before uploading Python code to code-sharing places shuch as github.

Example: A function in Python can be named with any combination of lowercase and uppercase letters. But according to the style guide, only lowercase letters should be used for functions, and spaces should be converted into underscores (see snake case vs. camel case)

So called code formatters are programs to modify code so that the code follows the rules of a style guide. A very popular Python code formatter is black. Links:

print()

print command TODO

prompt

prompts are a piece of text to indicate that the user shall type something (like typing his name or a password.). See input() and IDLE.

Python

The Python programming language was invented by Gudio van Rossum.

The name originates from Guido’s love for the british acting group →Monty Python. The Python logo symbolises two python snakes:

Python logo

random

The random module is a collection of useful functions about generating random numbers. See the official documentation: https://docs.python.org/3/library/random.html.

random.randint()

Creates an random integer. Python documentation: https://docs.python.org/3/library/random.html#random.randint

  random.randint(a, b)
  Return a random integer N such that a <= N <= b. 

Example:

1import random
2result = random.randint(1,6)  # simulates a six-sided die throw
3print(result)
range()

In-buildt Python function. Python documentation: https://docs.python.org/3/library/stdtypes.html?highlight=range#range

raise

keyword to raise an Error or exception. TODO: link, example

REPL

Rapid Evaluation Print Loop. To test out short line(s) of Python code directly. See also idle.

return

the return keyword can only be written inside of a function. It ends the function, the program continues in the line with the function call. A value (usually, a variable) can be written right of the return keyword, this is the return value. TODO: link, example

return value

the return value of a function. TODO: more specific, example

scope

the scope of a variable defines where she “lives” or is visible:

  • global scope: a variable defined at “root level” (at the left edge of the coding area) is visible in all functions and classes “below” it (code that is indented to the right)

  • local scope: a variable defined inside of a class or function is only visible inside this class/function and all classes/functions “below” it (more indented to the right)

TODO: link, examples

set

see data structure

string

Any number of characters (including numbers) that are enclosed in quotes (either single quotes ' or double quotes ") are called a string. If the string is enclosed in triple quotes (''' or ''') the string can span over several physical lines. See also docstring. Strings are not mutable Strings are iterable

string.format()

the .format() method of strings allows it to replace placeholders (curly brackets) with variables. See also {ŧerm}f-string. See also Format Specification Mini Language. Example:

name = "Alice"
print("Welcome {}, how do you do?".format(name))
# ouput is: "Welcome Alice, how do you do?"
string.lower()

the .lower() method of strings creates a copy of the original string in lowercase. Example:

names = "Alice and Bob"
print("copy:", names.lower())
print("original:", names)
# output is:
# copy: alice and bob
# original: Alice and Bob
string.upper()

the .upper() method of strings creates a copy of the original string in uppercase. See string.lower()

text based user interface

see user interface

third party library

A software (usually a module) that is not included in the official Python version. To be able to make use of such software, it must first be installed and only then can be importet.

Example: To use the third-party library PySimpleGUI it must first be installed via a pip command:

pip install pysimplegui

and only after such an installation, it can be used inside Python:

1import PySimpleGUI as sg
2sg.PopupOK("Hello World")   # creates a Dialog box
try

part of an tryexcept block. The command(s) inside this tryexcept block are executed. But unlike normal commands, if an error occurs, the program does not stop with an error message but instead continues with the commands after the except line. TODO: example, link

True

a boolean value. See also False. TODO: everything != 0 is True? link?

TUI

see user interface

tuple

see data structure

type hint

see official documentation: https://docs.python.org/3/glossary.html#term-type-hint

Type hints are optional and are not enforced by Python but they are useful to static type analysis tools, and aid IDEs with code completion and refactoring.

unittest

see official Python documentation at https://docs.python.org/3/library/unittest.html?highlight=unittest#module-unittest

user interface

A →user interface (UI) is the space where interactions between humans and machines occur.

A →graphical user interace (GUI) involves widgets such as buttons, sliders and entry fields where the user can interact with the computer, typically by using mouse and keyboard.

A →text based user interface (TUI) is an older, more simple form of User interface and does not require that the computer can draw graphics, because only text is displayed. While some modern variants of TUI’s support the use of colors for display and mouse for navigation, a typical TUI can be navigated only by keyboard and uses only one color.

In Python, the commands input and print are sufficient to create a little TUI.

ValueError

an error that can raise by code inside of an try .. except block. See official documentation: https://docs.python.org/3/library/exceptions.html?highlight=valueerror#ValueError

while

Python keyword to start a loop. The loop is executed as long as the expression right or while remains True. TODO: example, link

widget

The elements inside a GUI. For example buttons, sliders, fields to enter a password etc. Modern TUIs can also have widgets, typically made out of (colored) text.

zip()

The zip function can merge seveal iterables together. TODO: example TODO: link to official docu