What is Python? Hello World!

What is Python? Hello World! Titelbild

What is Python?

Python or rather Pythonidae is the name of a family of snakes. It also happens to be the name of a a great programming language. Python is quite easy to learn and also offers a lot of useful functions. It is a great start for new programmers but also interesting for people who already have programming knowledge. It is also really easy to use python on the Raspberry Pi, so let’s get started.

This is what a line of Python code looks like:

print(“Hi! I’m Python”)

Okay that was easy. And this is what it looks like if we add a second line to the program:

print(“Hi! I’m Python”)
favoriteFood = “Apples”

Da Programmierer sich das Leben gerne etwas leichter machen, achten sie nicht immer auf korrekte Rechtschreibung. Wörter werden zum Beispiel am Anfang mal klein geschrieben und an diese wird dann ohne Leertaste etwas Neues dran gehängt. Wundere dich also nicht, wenn dir die Rechtschreibung im Programmcode mal komisch vorkommt. Achte bitte auch darauf, dass ein Programm von oben nach unten durchläuft. Also von der ersten Zeile bis zur letzen. Wenn du mehr darüber erfahren möchtest, wie der Python-Interpreter funktioniert, schau auf unserer Lernplattform vorbei. Viele Zeilen Programmcode ergeben am Ende ein tolles Programm. Was wohl das zweizeilige Programm von dieser Seite alles bewerkstelligen kann?

Hello world

As you may have noticed, it is a long standing tradition that a beginner for a new programming language starts with a hello world program and we of course don’t want to break with this tradition. This program is quite simple and just prints the great words “Hello World” into the terminal. To do this with your Pi, you first need to be in your home folder. You then need to have an editor in place to write and save your program. For this we can use the preinstalled program nano. Just type the following command and press the Enter-Key:

This terminal command will start an editing and writing program within the terminal. This is a really simple program but it is great to take our first steps. After the program we are defining the file in which we want to save our program. hello-world is the name and .py is a reference that this code isn’t just any code but python code in particular. You don’t need to write the $ into the command line, it should already be in the terminal. After entering the command you should see a nearly empty window which is waiting for your first program to be written. When you write your program into the nano editor you don’t need to copy the line numbers. We have entered these in our Python code for better understanding. Please enter the following code:

print("Hello World, how are you?")

This is all you need for your first Python program. After typing the code you only need to save the program by first pressing Ctrl and x. The lower part of the screen should change to this:

You need to type a y in the the following dialogue in order to save the changes. Next press enter if you don’t want to rename your file.

Ready! You have now created a new file with the name hello-world.py and inside this file is your newly written Python program. You can use the same command again if you want to change anything in the file. The only thing left to do is start your program. To do this just type the following terminal command:

python3 hello-world.py

It should now look like this in your terminal. And just like that you just wrote your first Python code on a Raspberry Pi! That is super cool!

If it didn’t work for the first time do not fret. Just look at all the instructions again and if necessary repeat all the steps above.

It’s your turn

You can always edit your code with the comand nano name-of-file.py.

nano hello-world.py

The nano editor will look like the last time but this time your old written code is already saved inside. Please take this chance to edit the text which is printed (maybe insert your name), then save the code and execute it again. Are you now able to tell your computer what you want? Play around with the code and have fun!

Noch Fragen oder Feedback?

Bevor du eine Frage stellen kannst musst du dich zuerst Anmelden oder Regestrieren!