Skip to content
LessonItem 1 of 36

What Is a Program and Why Learn Python?

You are viewing a preview. Enroll to save your progress.

Every morning at school there is a cleaning roster: who sweeps, who wipes the whiteboard, who takes out the rubbish. That roster is a list of instructions carried out in order. A computer program works the same way: a list of instructions written in a language the computer understands, then carried out one by one from top to bottom.

Why Python?

Python is a programming language that reads like simple English, so it is easy for beginners to read. Even though it is easy, Python is used for real work by data scientists, website builders, artificial intelligence researchers and engineers at large companies. If you have used Scratch before, the ideas are the same: commands, sequence, repetition and decisions. The difference is that in Python you type the commands instead of snapping blocks together.

How Python reads your program

A Python program is run by another program called the interpreter. The interpreter reads your code line by line from top to bottom. Look at this example:

Python
print("Selamat pagi, kelas 7B!")
print("Hari ini jadwal piket: Rina dan Bayu")
print(2 + 3)

Step by step, Python does this:

  1. It reads the first line, sees the print command, and displays the text inside the quotation marks.
  2. It moves to the second line and displays the next text.
  3. The third line has no quotation marks, so Python calculates 2 + 3 and displays 5.

Text inside quotation marks is called a string. Python displays it exactly as written. Numbers without quotation marks are calculated. So print("2 + 3") displays the text 2 + 3, while print(2 + 3) displays 5.

Comments

A line that starts with # is a comment. Python skips it, but people can read it. Use comments to explain what your code is meant to do, for a classmate or for your future self.

Python
# Program pengumuman kelas
print("Jangan lupa membawa buku paket IPA")
Remember: the computer does not guess what you mean. It runs exactly what you wrote, typos included. That is why programmers are careful and test their work often.