1. Commands
Program — it's a set (or list) of commands. First, the first command gets executed, then the second, the third, and so on. When all the commands are done, the program finishes.
What kind of commands can be on the list depends on who is executing them: what commands the executor knows (and understands). You can tell a dog 🐕 to "Sit", "Speak", a cat 🐈 — "Shoo!", a person — "Stop! I'll shoot!", and a robot 🔧 — "Work! Work, you robomother!"
Programs written in Python are executed by py.exe (Python Interpreter).
Python Interpreter — is a special program that knows how to execute
code written in Python.
Its list of commands is pretty extensive. For example, this command can display "Robot is a friend of humans" on the screen:
print("Robot is a friend of humans")
But we're not diving straight into commands, we'll start with a couple of simple principles. Knowing a few principles can replace knowing a lot of facts.
2. Basic Python Principles
First principle: In Python, it's customary to write each command on a new line.
Suppose we want to print "Robot is a friend of humans" to the screen 3 times. Here's how the program code would look:
print("Robot is a friend of humans")
print("Robot is a friend of humans")
print("Robot is a friend of humans")
Second principle: The number of spaces (indentation) at the beginning of a line is super important.
This is a unique feature of Python
. Commands that follow each other must have
the same amount of indentation (spaces) at the start. This code won’t work:
print("Robot is a friend of humans")
print("Robot is a friend of humans")
print("Robot is a friend of humans")
Third principle: Commands are grouped using indentation from the left.
If several commands have
the same amount of indentation on the left
, they're considered
part of the same block. Example:
for name in ["Masha","Katya","Anya"]:
print("Robot is a friend of humans")
print(f"{name} is a friend of robots")
You’ll learn more about code blocks in the upcoming lectures.
3. First Program
It's time to write your first program. Why put off such a good thing for later?
Usually, the first program is all about displaying some basic text on the screen, like
Hello, World!
. But honestly, that's way too basic.
Your first program should be something you'll remember forever.
Come up with a bright, pompous, and memorable phrase.
If you can’t think of anything, here are some suggestions:
- “It is inevitable. It is your destiny.”
- “Do what must be done, Lord Vader. Do not hesitate. Show no mercy.”
- “The dark side of the Force is a pathway to many abilities some consider to be unnatural.”
But before we jump into writing the first program, let me show you where you’ll actually be coding.
GO TO FULL VERSION