Victor Jeman - Frontend Architectv3.0
Python Fundamentals8 min

Meet Python

Discover what Python is, why it is popular, and write your first program.

What You'll Learn

  • Understand what Python is and why it is one of the most popular languages
  • Write and run your first Python program
  • Use the print() function to display messages on screen

You know that moment in an RPG when you unlock a new ability and suddenly everything changes? You can access new areas, solve puzzles you used to skip, do things you never thought possible. Well, that is about to happen to you right now, except in real life. The ability you are unlocking today is called Python.

Python is a programming language, meaning it is a way to tell the computer what to do. But not just any language, it is considered one of the friendliest programming languages in the world. If other languages look like a recipe written in hieroglyphs, Python looks almost like a normal sentence in English. And that makes it perfect for someone just getting started.

By the end of this lesson, you will have already written your first program. Seriously. Not in a week, not after ten tutorials, today. Let's go.

In this lesson you begin building Python Kingdom, a text RPG game where your hero will traverse 9 lands to defeat the evil Dark Bug. In each lesson you will add a new feature to the game, and by the end you will have a complete RPG! Today you create the title screen, the kingdom map, and the story introduction, using print() and comments.

What is Python, really?

Python was created in 1991 by a Dutch programmer named Guido van Rossum. And do you know where the name comes from? Not from the python snake, as you might think. Guido was a fan of the British comedy group Monty Python, so he decided to give the language this funny name. So yes, programming can be fun too.

The idea behind Python was simple: create a language that people could read easily, not just computers. And he succeeded. Today, Python is used by millions of people around the world, from high school students to engineers at the biggest tech companies.

Why learn Python specifically?

You might be wondering: "There are a ton of programming languages out there. Why Python?" Here are a few solid reasons:

  • It is easy to read. Python code looks clean and organized. You do not need tons of weird symbols to make something work.
  • It is versatile. You can do almost anything with it: from games to web apps, from data analysis to artificial intelligence.
  • It has a huge community. If you get stuck on something, chances are someone else had the same problem and posted the solution online.
  • It is in demand on the job market. Companies look for Python programmers for all kinds of interesting projects.

What can you build with Python?

Let me give you some concrete examples to give you an idea:

  • Games - you can create 2D games with a library called Pygame. We are not talking about Fortnite, but you can make a Snake game or an interactive quiz.
  • Websites - platforms like Instagram were initially built with Python, using a framework called Django.
  • Artificial intelligence - chatbots, image recognition, weather predictions - many of these are built with Python.
  • Automation - have a boring task you repeat daily on your computer? Python can do it for you in seconds.
  • Data analysis - if you want to discover patterns in large datasets, Python is the number one tool.

How to run Python

To write and run Python code, you have a few options. The fastest way to get started is to use an online editor right in your browser, without installing anything. I recommend repl.it. Go to the site, create a free account, choose "Python" as the language, and you are good to go.

If you want to work on your own computer, you can download Python from python.org and use a code editor like Visual Studio Code. But for now, repl.it is more than enough.

Your first program: Hello, World!

There is a tradition in programming: the first thing you do when learning a new language is to display the message "Hello, World!" on screen. It is like a greeting you give to the programming world. Let's honor the tradition:

That is it. One single line. When you run this code, the screen will show:

text
Hello, World!

The print() function is the one doing the magic. You give it some text between quotes and it displays it on screen. Simple and elegant.

Play around with print()

Now that you understand the basic idea, let's experiment a little. You can display any message you want:

Each print() displays its text on a new line. So the result would be:

text
Hi, I am a 9th grade student!
I like to play Minecraft.
Today I am learning Python!

You can glue two texts together using the + operator. This is called concatenation (a fancy word that simply means "joining"):

Will display:

text
My name is Alex

Pay attention to the space after "is ". Without it, the texts would stick together directly and you would get "My name isAlex", which does not look great.

You can also use print() with numbers, without quotes:

Will display 15, because Python calculates the result before displaying it.

Comments - notes to yourself

When you write code, sometimes you want to leave a note for yourself or for someone else reading the code. Maybe you want to explain why you did something in a certain way. That is what comments are for.

In Python, a comment starts with the # symbol. Everything after # on that line is completely ignored by the program:

Comments are extremely useful. Think of them as sticky notes you put in your notebook. The computer does not read them, but you will appreciate them when you come back to your code a week later and cannot remember what you were trying to do.

A good habit is to write short and clear comments. You do not need to comment every line, just the parts that might be confusing.

Python is a programming language created by Guido van Rossum, easy to read and extremely versatile. The print() function lets you display text and numbers on screen. Comments start with # and are ignored by the program. You use them as notes to yourself.

Exercise : The title screen of Python Kingdom

Create the title screen for the game "Python Kingdom". Display the game title framed inside a border of # characters, with the subtitle "The Curse of Dark Bug" below it. Use print() for each line and add a comment explaining what the program does.

Exercise : The hero's message

The game's hero needs to introduce themselves. Use print() and concatenation with + to display a welcome message. The program must display: "Welcome, traveler!", then on the next line "You are the last hero of Python Kingdom." and on the third line "Your mission: defeat Dark Bug!". Use concatenation for at least one line.

Exercise : Map of Python Kingdom

Create an ASCII map of Python Kingdom showing 3 locations connected to each other: "Starting Village" in the center, "Shadow Forest" above, and "Bugged Castle" below. Connect them with lines using | and --- characters. Add a title "KINGDOM MAP" above the map and a comment explaining what the map represents.

Exercise : Introduction to the story

Create a narrative "loading screen" for the game. Display a text of 5-6 lines that briefly tells the legend of Python Kingdom: the kingdom was cursed by Dark Bug, a hero must traverse 9 lands and restore peace. End with the message "Your adventure begins now...". Add comments that separate the sections.

Exercise : Your digital business card

Create a small program that displays a "business card" with your info: name, age, city, favorite hobby, and favorite school subject. Each piece of info must be on a separate line. Use concatenation with + for at least one of the lines.

Exercise : Countdown to launch

Write a program that displays a countdown from 5 to 1, followed by the message "Liftoff!". Each number must appear on its own line. Add a comment explaining what the program does.

Complete game code: Python Kingdom (Lesson 1)

Congratulations! You have created the first elements of the Python Kingdom game. Copy the code below into a .py file and run it to see the full title screen:

Test Your Knowledge

Check how well you understood the lesson with these 5 questions.

Question 1 of 5

Who created the Python language?