Introduction to the Python language

The basics, with Python

What is Python?

Python is a widely used high-level, general-purpose, interpreted”), dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code that would be possible in languages such as C++ or Java.

Source: Wikipedia

To get familiar with Python programming language during this week you need to go through some interactive tutorials. You can find the tutorial here:

https://www.sololearn.com/Course/Python/

You can register for Sololearn with your Google account. We will refer to the particular sections of this tutorial like this: Module number e.g.: you can read about python in Module 1 (Basic concepts / 1).

History of Python (optional)

(This is an optional section of the curriculum, no one will ask you about it)

You can read short articles about the language:

Also, you can hear the short version from the main author himself:

Where to write the code?

There are 2 ways to run the Python Interpreter:

Using the interactive shell: http://www.python-course.eu/python3_interactive.php

Executing a script file: http://www.python-course.eu/python3_execute_script.php

(Please read, follow and try out both tutorials)

Note that we made an alias to python3 as python during the installation of Ubuntu, so for you, Python 3.x is the default version.

[Additional article if you are interested how things work in the background: https://docs.python.org/3/tutorial/interpreter.html]

[Extra tutorials: https://alison.com/topic/learn/2971/36729/module-1-introduction-to-programming-with-python/introduction-to-programs-data-types-and-variables, https://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Hello,_World]

How to structure the code?

Since Python uses indentations to define code blocks, it is important to write readable (and compile ready) code. When the code is not understandable by the interpreter, we talk about a syntactical error.

Please read this section: https://docs.python.org/3/reference/lexical_analysis.html#indentation

and this answer: https://docs.python.org/3/faq/design.html#why-does-python-use-indentation-for-grouping-of-statements

If the topic is still not clear to you, we recommend the following tutorial as well: http://www.python-course.eu/python3_blocks.php

Please follow the official styling guide: https://docs.python.org/3/tutorial/controlflow.html#intermezzo-coding-style

The magic

In this section, we collected tutorials from different sources. These are here to help you understand different topics, so they are not mandatory if you are confident with your current knowledge. Keep the week’s goal in mind and use these resources as you like. -> Try to do the assignments and use the tutorials as help.

Basic variables, concept

Until now, we used expressions (like: 4 and 2+2 and “this is a string”) to print something out. But if we want to reuse a value, we gonna need some variables and of course we would like to operate on them…

  • Module 1 (Basic concepts)

Conditions

  • Module 2 (Control structures / 1-4)

While Loops

Lists and Strings

For Loops

Copying of a variable

Functions

User interaction

File handling

You can watch this video which can help you to summarize the topics above in half an hour. Only the first 30 minutes is related to the introduced fields: