Zu Hauptinhalt springen

Einführung ins Programmieren mit Python (52806, 4SWSt, 6 LPs)


Python Logo(Bild aus Wikipedia)

(English Version Below)

Die Sprache Python – benannt nach der britischen Anarcho-Komiker-Truppy Monty Python – ist sicherlich kein Witz. Erstmals veröffentlicht im Jahre 1990 und seither kontinuierlich weiterentwickelt hat Python sich einen festen Platz in der Welt des Programmierens erkämpft. Besonders in der Welt des Machine Learning und für wissenschaftliche Anwendungen erfreut sich die Sprache großer Beliebtheit. Neben dem Sprachdesign, das schnelle und flexible Entwicklung erlaubt, ist die Verfügbarkeit von vorgefertigten Libraries (Sammlungen von Programmroutinen aus Bereichen wie Linearer Algebra, Grafischen User-Interfaces oder Datenanalyse) ein großer Pluspunkt.

In The Zen Of Python wird die Philosophie der Sprache zusammengefasst in den Punkten:

  • Beautiful is better than ugly.
  • Explicit is better than implicit.
  • Simple is better than complex.
  • Complex is better than complicated.
  • Readability counts.

Entsprechend diesen Maximen wird im Kurs Einführung ins Programmieren mit Python in einfachen Schritten gezeigt, welche Bauelemente die Sprache Python bietet, und wie mit diesen komplexe Aufgaben bewältigt werden können. Dabei wird auch einige Energie auf allgemeine Ideen der Algorithmik verwendet, also auf Konzepte, die auch außerhalb der Welt von Python eingesetzt werden können.

Derzeit sind sowohl die Version 2.7 und 3.8 der Sprache Python gängig. Die beiden Versionen unterscheiden sich nur in wenigen Punkten, sind prinzipiell nicht kompatibel. Im Kurs wird das modernere Python 3 gelehrt.

Die Universität Regensburg bietet einen Anfängerkurs für Studierende ohne Vorkenntnisse sowie einen Aufbaukurs, der im Anschluss an den Anfängerkurs gehört werden kann. Beide Kurse stehen grundsätzlich allen Studierenden der Universität Regensburg und der OTH offen. Mathematische Denkweise und Grundkenntnisse auf Gymnasialniveau werden vorausgesetzt (siehe Abschnitt Ablauf und Kursanforderungen). Im Fortgeschrittenenkurs wird ein Fokus auf Fragestellungen der Naturwissenschaften gelegt (z.B. Integration, Fourieranalyse, ...); siehe hierzu den Abschnitt Behandelte Themen.

Studierende mit Vorkenntnissen sind zum Fortgeschrittenenkurs gerne gesehen, auch wenn der Anfängerkurs nicht besucht wurde. Siehe hierzu der Abschnitt Behandelte Themen, um abzuschätzen, ob entsprechende Vorkenntnisse gegeben sind. Nehmen Sie im Zweifel Kontakt zum Dozenten auf. Unter dem Abschnitt Literatur finden Sie das Lehrbuch "Programmieren in Python" (Deutsch), das im Anfängerkurs verwendet wird und zum Selbststudium geeignet sein sollte. (Das Buch ist leider noch nicht vollständig, umfasst aber bereits alle Themen des Anfängerkurses.)

Vorlesungssprache ist Englisch; in der ersten Vorlesungseinheit kann aber über auch über die Vorlesungssprache Deutsch abgestimmt werden. Wenn international students an der Vorlesung teilnehmen, muss der Kurs auf Englisch gehalten werden. Bitte haben Sie Verständnis dafür, dass die meisten Lehrmaterialien nur in Englischer Sprache zur Verfügung stehen (einzige Ausnahme ist das Lehrbuch Programmieren in Python, das nur auf Deutsch zur Verfügung steht).


(English Version)

The programming language Python – named after the Britsh Comedians Monty Python – should never be discounted as a joke. Since its publication in 1990, the language has been improved upon continuosly and earned its status as one of the most popular scripting languages in the programming community. In particular, Python is a great choice for applications such as machine learning and scientific computing. The design of the language as well as the large set of freely available libraries (collections of routines, e.g. for linear algebra, graphical user interfaces or data analysis) allow for quick and flexible development of IT solutions and are a major reason for many developers to choose Python as their main language.

The manifesto of the developers of the language, titled The Zen of Python summarizes the philosophy of Python's design in these few bullet points:

  • Beautiful is better than ugly.
  • Explicit is better than implicit.
  • Simple is better than complex.
  • Complex is better than complicated.
  • Readability counts.

Following these paradigms, the course Introduction to Programming in Python shows in simple lessons the language Elements of Python and how to combine and use them to solve complex problems. A noticeable portion of the course will be general considerations of algorithms, i.e. concepts that will be useful also when learning languages other than Python.

Currently, both versions 2.7 and 3.8 of the language Python are commonly in use. They differ only in minor details, but are in principle not compatible. The course covers the more modern Python 3.

The University of Regensburg currently offers an introductory course for students with no prior knowledge in programming, as well as an advanced course that is meant as a continuation of the introductory course. Both courses are open for all students of the Universität Regensburg and of OTH. Students should be proficient in mathematical thinking and bring "high school maths" knowledge (See section Details and Prerequisites). The advanced course will focus on questions from the natural sciences (e.g. integration, Fourier analysis, ...). See section Covered Topics for details.

Students with prior knowledge are welcome to the advanced class, even if they did not follow the introductory class. See section covered topics as a reference on what knowledge will be expected in the advanced course. In the section literature you will find the book "Programmieren in Python" (German) that also doubles as lecture notes. You can use the table of contents to gauge the expected level of proficiency in Python for the advanced class. Feel free to contact the lecturer if you have any questions.

The lecture will be held in English unless unanimously decided otherwise in the first lecture unit (Options will be German and English). Please understand that most lecture materials are available in English only, with the exception of the aforementioned book Programmieren in Python.


Ablauf und Kursanforderungen / Details and Prerequisites

(Englisch Version Below)

Der Anfänger-Kurs wendet sich an Anfänger ohne Vorkenntnisse im Programmieren; im Fortgeschrittenen-Kurs wird auf die Erkenntnisse des Anfänger-Kurses aufgebaut, wobei ein Fokus auf naturwissenschaftliche Fragestellungen gelegt wird. Die Kerninhalte beider Angebote werden in einer wöchentlichen Vorlesung (Semesterkurs) bzw. an den Vormittagen des Blockkurses vermittelt (Siehe Abschnitt Termine).

Beachten Sie aber, dass Programmieren eine Form von angewandter Mathematik ist. Gymnasial-Mathematik (abstrakte Ausdrücke mit Platzhaltern; komplexe Zahlen; Matrizen; Ableitungen) wird vorausgesetzt. Rechner gehen mit Zahlen um; wenn Sie an der Schul-Mathematik verzweifelt sind, werden Sie am Programmieren ebenfalls keinen Spaß haben.
Für den Fortgeschrittenen-Kurs wird der Fokus auf Fragestellungen aus der Physik und Mathematik gelegt.

Neben dem Besuch der Vorlesung sind die Übungsstunden in Kleingruppen (ca. 10 TeilnehmerInnen) essentiell. TeilnehmerInnen können hier in Gruppen bis zu drei Personen an den Übungsaufgaben arbeiten und erhalten Unterstützung von erfahrenen TutorInnen. Die erfolgreiche Teilnahme am Übungsbetrieb gilt als Studienleistung und ist Voraussetzung für den Abschluss des Kurses. Weiter bearbeiten die KursteilnehmerInnen ein selbstgewähltes Problem als Abschlussprojekt. Vorschläge für Abschlussprojekte werden im Kurs genannt. Das Projekt kann mit bis zu zwei PartnerInnen in Teamarbeit bearbeitet werden.

Erfolgreiche Teilnahme am Übungsbetrieb heißt dabei, dass 75% der Punkte für die Aufgaben zur Selbstprüfung erreicht werden müssen. Zusätzlich soll jede/r Teilnehmende mehrere Male pro Semester (abhängig von der Teilnehmerzahl) seine/ihre Lösungen mit den TutorInnen durchsprechen.

Im Fortgeschrittenenkurs kann alternativ zum Abschlussprojekt auch ein ca. 30minütiger Seminarvortrag gehalten werden. Der Seminarvortrag kann alleine oder in Gruppen bis zu zwei Vortragenden ausgearbeitet werden. Bitte haben Sie Verständnis dafür, dass nur maximal 6 Vorträge im Semester möglich sind, d.h. dass ggf. nicht jede Gruppe, diesen Prüfungsmodus wählen kann.

Die Programmierübungen können auf den CIP-Pool-Rechnern der Universität oder auf dem eigenen Rechner durchgeführt werden. Dazu muss ein Python-Interpreter sowie eine Arbeitsumgebung installiert werden. Auf den Pool-Rechnern ist dies bereits geschehen. Entsprechend kundige TeilnehmerInnen, die den eigenen Rechner verwenden wollen, werden gebeten, bereits vorab die Installation umzusetzen. Hierzu wird folgende Installation empfohlen:

(Auf gängigen Linux-Distributionen ist Python 3 bereits vorinstalliert. Sollte dies nicht der Fall sein, benutzen Sie bitte den Package-Manager Ihrer Wahl und installieren Sie die Packages python3.9 und python3.9-dev aus dem Repository ppa:deadsnakes/ppa)

Siehe zu allen Betriebssystemen auch den Beginners Guide for Installing Python 3

Sofern Sie nicht der o.g. Schritt-für-Schritt-Anleitung folgen können oder wollen, empfehle ich als Arbeitsumgebung, den entweder den Code-Editor Spyder oder Notepad++ zu installieren:

  • Homepage Spyder
    Die IDE (Integrated Development Environment) ist als Arbeitsumgebung beginnerfreundlich, und erlaubt eine einfache Bedienung der Komponenten von Python, ohne tiefere Kenntnisse des Systems vorauszusetzen.
  • Homepage Notepad++
    Notepad++ ist ein sehr schlanker und vielseitig verwendbarer Code-Editor. Insbesondere TeilnehmerInnen, die sich vorstellen können, auch andere Programmiersprachen zu erlernen sei dieser Editor nahegelegt.

(English Version)

The introductory course is directed towards beginners with no prior knowledge in programming; the advanced class is based upon the skills conveyed in the introductory class and will focus on questions from natural sciences. The core concepts of programming in Python will be explained in a weekly lecture (semester corse) or on the mornings of the block course (See section Dates). 

Please be aware of the fact that programming is a form of applied maths. High school maths (abstract expressions with place holders for other expressions, complex numbers, matrices, derivatives) are assumed to be well understood by students. Computers deal with numbers; if you didn't like maths in school, you won't have much fun at programming either.
The focus of the advanced course will be on questions motivated from physics and maths.

Additionally to the lectures there will be a weekly (semester course) or daily (block course) tutorial class in small groups (ca. 10 participants per group). Students can use this as an opportunity to ask questions and will be given exercise sheets. Students may work on these exercise problems alone or in groups of up to three participants. They will be required to hand in 75% of these exercise problems as part of the course. The solutions to the exercise problems should be presented to the tutors several times in the course (depending on the group size, frequence may vary).

Furthermore, a final project marks the culmination of the course. Participants may pick a recommended project or come up with own ideas which may be handed in as a final project after discussing the scope of the project with the lecturer.

In the advanced course, it is possible to give a presentation of ca. 30 minutes as an alternative to the final project. This presentation may be done alone or with a partner. Please understand that at most six groups may opt for this mode of passing the class, i.e. it is possible that groups have to be rejected when there are many students who want to do presentations instead of writing code.

Programming exercises and the final project can be done on the CIP pool computers of the university or on the private computers of the participants. If you want to use your own computer, it is required to install a development environment. Please prepare this installation by following this step-by-step guide:

(Usually, Linux installations come with Python3 pre-installed. Where this is not the case, please use your package manager and install the packages python3.9 und python3.9-dev from the repository ppa:deadsnakes/ppa)

See also the Beginners Guide for Installing Python 3 for an alternative guide.

If you cannot or do not want to follow the instructions given in the step-by-step guide, it is recommended to install either Spyder (Windows, Mac, Linux), Notepad++ (Windows) or Geany (Linux, Mac) as Code editors.

  • Homepage Spyder
    This IDE (Integrated Development Environment) is very apt for beginners and allows using many of the features of python without demanding a deeper understanding of the system.
  • Homepage Notepad++
    Notepad++ is a light-weight and very versatile code editor. In particular, participants aspiring to learn programming languages other than Python may use this multi-purpose editor.

Behandelte Themen / Covered Topics

(English Version Below)

Der Anfängerkurs behandelt diese Themen:

  • Arbeitsumgebung: Interpreter und Compiler, Arbeitsverzeichnis, Kommunikation mit der Maschine
  • Grundlagen der Sprache Python: Variablen, Datentypen, Schleifen, Kontrollstrukturen
  • Objektorientierung: Klassen, Methoden, Dunders, Vererbung
  • Ausgewählte Pakete für die wissenschaftliche Arbeit: numpy, matplotlib

Aufbauend auf diesen Kenntnissen wird im Fortgeschrittenenkurs voraussichtlich folgendes besprochen:

  • Effizienz und Laufzeitanalyse
  • Iterators
  • Decorators
  • Modul SciPy (Routinen für Naturwissenschafte Anwendungen)
  • Modul tkInter (Graphische User Interfaces)
  • Modul pandas (Arbeit mit Data Frames aka Tabellen)
  • Module os and sys, glob (Zugriffe auf das Dateisystem)
  • Machine Learning: Grundideen
  • Hilfsmittel: git, docstrings, type annotations, ...

Beachten Sie bitte, dass die Beispiele im Fortgeschrittenen-Kurs häufig aus der Physik und Mathematik heraus motiviert sind. 


(English Version)

The introductory course covers

  • Programming Environment: Interpreter und Compiler, working directory, communication schemes
  • Basics of the language Python: variables, data types, loops and controll structures
  • Object oriented programming: classes, methods, dunders, inheritance
  • Selected libraries for scientific programming: numpy, matplotlib

Based upon this, the advanced course discusses:

  • Efficiency and Runtime Analysis
  • Iterators
  • Decorators
  • Modul SciPy (Routinen für Naturwissenschafte Anwendungen)
  • Modul tkInter (Graphical User Interfaces)
  • Modul pandas (Manipulating Data in Frames aka tables)
  • Module os and sys, glob (Interacting with the File System)
  • Machine Learning: Basic Ideas
  • Auxillary tools: git, docstrings, type annotations, ...

Please be aware that the examples in the advanced class are often motivated by questions physics and maths.


Termine / Dates

(English Version below)

Der Anfängerkurs findet dreimal jährlich statt: als Semesterkurs im Wintersemester sowie als Blockkurs zwischen Winter- und Sommersemester bzw. zwischen Sommer- und Wintersemester. Der Fortgeschrittenenkurs wird bisher nur im Sommersemester angeboten.

Blockkurse finden ganztags statt (Vorlesung von 9-12:00, Übungen von 13-17:00). Die Semesterkurse umfassen eine wöchentliche Vorlesung (2 SWS) sowie eine wöchentliche Übung (2 SWS).

Fehlen an einzelnen Tagen ist grundsätzlich kein Problem; natürlich müssen die verpassten Inhalte dann selbstständig nachgeholt werden. Hierzu können Sie u.a. die Mediathek (Kanäle → Physik → [Suche nach Python]) nutzen, in der Aufnahmen aus dem laufenden Kurs sowie aus den Vorjahren zur Verfügung stehen. Weiter stehen ihnen verschiedene Texte sowie die VL-Folien über GRIPS zur Verfügung.

Unter diesem Link finden Sie die genauen Kurstage für die Blockkurse.


(English Version)

The introductory course is offered three times per year: as a semester course in each winter term as well as as block course between the winter- and summer term and between the summer- and winter term respectively. The advanced course is only offered in the summer term.

Block courses take the whole day (lecture from 9 AM till 12 PM, exercises from 1 PM till 5 PM). In semester, there will be a weekly lecture (2 hours) and a weekly exercise (2 hours).

Missing out on single days is okay, if you cover the treated material yourself. To that end you can use the recorded videos from the previous years and the current year. See Mediathek  (Kanäle → Physik → [Search forPython]). Further you have a textbook as well as the materials provided on GRIPS to cover missed content.

See this link for an overview of the block courses.


Literatur

Anmeldung zum Kurs / Registration

(English Version below)
Die Anmeldung zum Kurs sollte über das Exa stattfinden. Jeweils zum Semesterende finden Sie die Python-Kurse (sowohl Semester- als auch Blockkurse) im Vorlesungsverzeichnis unter:

Lehrveranstaltungen der Fakultät für Physik / Courses in Physics -> Master Course in Physics / Studiengang Master Physik -> Special Topics Lectures / Spezialvorlesungen.

Dabei werden die Blockkurse immer dem folgenden Semester zugeordnet, d.h. der Blockkurs im Juli zählt tatsächlich schon zum Wintersemester.

Sollten Sie keinen Zugriff auf das Exa/Spur haben (z.B. OTH-Studierende, MitarbeiterInnen, DoktorandInnen und Postdocs), können Sie gerne eine Mail an den Dozenten schicken.


(English Version)

To regeister for this course, please use the LSF system. Courses will be published at the end of each semester (this holds for both, semester as well as block courses). You find them by following this tree:

Lehrveranstaltungen der Fakultät für Physik / Courses in Physics -> Master Course in Physics / Studiengang Master Physik -> Special Topics Lectures / Spezialvorlesungen.

The block courses are registered in the subsequent semester, i.e. the block course taking place in July actually can be found in the LSF entries for the winter term.

If you cannot access the Exa/Spur system (e.g. OTH students, UR employees, PhD students and postdocs), you can register by sending an email to the lecturer.



Fragen zum Kurs können gern per Mail an den Dozenten Sebastian Lahrtz (Sebastian.Lahrtz@stud.uni-regensburg.de) gerichtet werden.

Da ich selbst noch Student bin, bevorzuge ich, geduzt zu werden ;)


Fakultät Physik - Studium

Universitätsstrasse 31
93053 Regensburg


Tel. +49 941 943 2023