Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

[1]

Basis data typesยถ

Getallenยถ

3 <class 'int'>
4
2
6
9
4
8
<class 'float'>
2.5 3.5 5.0 6.25

Booleansยถ

<class 'bool'>
False
True
False
True

Stringsยถ

hello 5
hello world
hello world 12
Hello
HELLO
  hello
 hello 
he(ell)(ell)o
world

Containersยถ

Listsยถ

[3, 1, 2] 2
2
[3, 1, 'foo']
[3, 1, 'foo', 'bar']
bar [3, 1, 'foo']

Slicingยถ

[0, 1, 2, 3, 4]
[2, 3]
[2, 3, 4]
[0, 1]
[0, 1, 2, 3, 4]
[0, 1, 2, 3]
[0, 1, 8, 9, 4]

Loopingยถ

cat
dog
monkey
#1: cat
#2: dog
#3: monkey

List comprehensionsยถ

Eenvoudige loops kunnen in elegante one-liners uitgedrukt worden, inclusief condities.

[0, 1, 4, 9, 16]
[0, 1, 4, 9, 16]
[0, 4, 16]

Dictionariesยถ

Dit zijn containers (key, value) paren zoals Map in Java.

cute
True
wet
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[69], line 1
----> 1 print(d["monkey"])  # KeyError: 'monkey' not a key of d

KeyError: 'monkey'
N/A
wet
N/A
A person has 2 legs
A cat has 4 legs
A spider has 8 legs

Dictionary comprehensionsยถ

{0: 0, 2: 4, 4: 16}

Setsยถ

Een set is een ongeordende verzameling van unieke elementen.

True
False
True
3
3
2

Loopingยถ

Dit is identiek aan looping bij lijsten, maar de volgorde ligt niet vast.

#1: fish
#2: dog
#3: cat

Set comprehensionsยถ

{0, 1, 2, 3, 4, 5}

Tuplesยถ

Een tuple is een (immutable) geordende lijst van waarden. In vele opzichten zijn ze gelijkaardig aan lijsten. Een van de meest belangrijke verschillen is dat tuples, in tegenstelling tot lijsten, als dictionary keys en elementen van sets gebruikt kunnen worden.

<class 'tuple'>
5
1
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[80], line 1
----> 1 t[0] = 1

TypeError: 'tuple' object does not support item assignment

Functiesยถ

negative
zero
positive

Default argumenten

Hello, Bob!
HELLO, FRED

Classesยถ

Hello, Fred!
HELLO, FRED
Footnotesยถ