Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add slides from this year's course #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
SLIDES := output/Bytes\ and\ Strings.pdf \
output/Exceptions\ and\ Context\ managers.pdf \
output/Functions,\ Objects\ and\ Classes.pdf \
output/int\ and\ float.pdf \
output/The\ Language.pdf \
output/Modules\ and\ Packages.pdf \
output/Collections\ and\ Iterators.pdf \
output/Decorators\ and\ advanced\ Functions.pdf \
output/Comprehensions.pdf

PANDOC_COMMAND := pandoc

PANDOC_OPTIONS := -t beamer

.PHONY: clean all

all: $(SLIDES)

clean:
rm -rf output

output:
mkdir output

output/%.pdf: slides/%.md img $(wildcard img/*) | output
$(PANDOC_COMMAND) $(PANDOC_OPTIONS) -o "$@" "$<"
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Artemis Python Slides

These are the slides intended to be used for teaching the [Python 3](https://www.python.org/)
programming language in conjunction with the [Artemis](https://artemis-app.inf.tu-dresden.de/)
exercises.

## Building

To build the slides with pandoc execute:

```sh
make all
```

The resulting PDF files are located in the `output` directory.

## Slides

The slides dont have to be taught in a specific order, but the following one is recommended:

1. The Language

2. Bytes and Strings

3. Functions, Objects and Classes

4. int and float

5. Exceptions and Context managers

6. Modules and Packages

7. Collections and Iterators

8. Decorators and advanced Functions

9. Comprehensions

## Artemis exercises

Almost every slide has an accompanying exercise in the [iFSR Artemis Course](https://artemis-app.inf.tu-dresden.de/courses/6/exercises).

It is recommended that the exercises are started after teaching Functions, Objects and Classes.
Binary file added img/classes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/lambda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pypi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/sugar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/unicode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 41 additions & 17 deletions slides/Bytes and Strings.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Bytes and Strings

![Unicode Logo](img/unicode.png "https://commons.wikimedia.org/wiki/File:New_Unicode_logo.svg"){ height=75% }

---

## Strings
Expand All @@ -12,7 +14,7 @@

- can be created by enclosing text in `'single'` or `"double"` quotes (literals)

- the length can be determined by `len(string)`
- the length can be determined by [`len(string)`](https://docs.python.org/3/library/functions.html#len)

---

Expand All @@ -24,22 +26,31 @@

- always start with a backslash and can be disabled by writing `r"string"`

| Escape sequence | Result |
|-------------------|----------------------------------|
| \n | ASCII Linefeed |
| \t | ASCII Horizontal Tab |
| \\\\ | \\ |
| \\" | " (works with single quotes too) |
| Escape sequence | Result |
|---------------------|----------------------------------|
| \\n | ASCII Linefeed |
| \\t | ASCII Horizontal Tab |
| \\\\\\\\ | \\\\ |
| \\" | " (works with single quotes too) |

---

### Concatenation
### Operators

- strings can be concatenated by adding them using `+`

- doing so with [`str.join(strings)`](https://docs.python.org/3/library/stdtypes.html#str.join)
is more efficient when concatenating many strings

- using `*` with a string and an integer repeats the string

- `==` checks whether two strings are equal

(`!=` checks the opposite)

- do not use the `is` operator to perform value comparisions!


```python
# both are equal to "Hello World!"
"Hello" + " " + "World!"
Expand All @@ -55,30 +66,36 @@

- writing `:` without specifying a value defaults to the start and end of the string

- [`str.partition(seperator)`](https://docs.python.org/3/library/stdtypes.html#str.partition)
splits the string into the part before the first seperator, the seperator and the part after the seperator

- [`str.split(seperator)`](https://docs.python.org/3/library/stdtypes.html#str.split)
splits the string into a list of substrings at the seperator (opposite to `str.join`)

```python
# retuns "Hello"
# returns "Hello"
"Hello World!"[0:5]
"Hello World!"[:5]

# returns " "
"Hello World!"[5]
```

---

### Splitting

- [`str.partition(seperator)`](https://docs.python.org/3/library/stdtypes.html#str.partition)
splits the string into the part before the first seperator, the seperator and the part after the seperator

- [`str.split(seperator)`](https://docs.python.org/3/library/stdtypes.html#str.split)
splits the string into a list of substrings at the seperator (opposite to `str.join`)

```python
# returns ("Hello", " ", "World!")
before, seperator, after = "Hello World!".partition(" ")
before, seperator, after = \
"Hello World!".partition(" ")

# returns ("Hello World!", "", "")
"Hello World!".partition("not found")

# returns ["Hell", " W", "rld!"]
"Hello World!".split("o")
```

---

### Formatting
Expand Down Expand Up @@ -109,3 +126,10 @@
- literals are prefixed with `b`

- can be transformed into strings using [`bytes.decode(encoding)`](https://docs.python.org/3/library/stdtypes.html#bytes.decode)

- can be created from strings using [`str.encode(encoding)`](https://docs.python.org/3/library/stdtypes.html#str.encode)

```python
b"Hello W\xc3\xb6rld!".decode("utf8") == "Hello Wörld!"
b"Hello W\xc3\xb6rld!" == "Hello Wörld!".encode("utf8")
```
Loading