Python for Beginners: Learn to Code from Zero · Lesson 1 of 10

Lesson 1: Meet Python and Write Your First Program

What Python is, how to run it, and your first program with print(). Five minutes to your first working code.

Lesson 1: Meet Python and Write Your First Program

Python is a programming language: a way of giving instructions to a computer in words it can follow. It is popular because it reads almost like English, so beginners can focus on ideas instead of strange symbols. People use Python to build websites, analyse data, automate boring tasks and create artificial intelligence.

What you need

Install Python 3 from python.org (the website has installers for Windows, Mac and Linux), or use a free online Python editor in your browser if you cannot install anything. To check it works, open a terminal or command prompt and type python --version (on some systems python3 --version). You should see a version number starting with 3.

Your first program

A program is a list of instructions, run from top to bottom. The simplest instruction is print(), which shows text on the screen. Text goes inside quotation marks.

print("Namaste, world!")
print("I am learning Python")

Output:

Namaste, world!
I am learning Python

Each print() shows its text on a new line. Save the lines in a file called hello.py and run it with python hello.py, or type them straight into your online editor.

Comments: notes for humans

A line starting with # is a comment. Python ignores it, so you can leave notes to yourself and others.

# This line is a comment, Python skips it
print("Comments help people read code")  # a note at the end of a line

Output:

Comments help people read code

Four mistakes every beginner makes

  • Capital letters matter. Print is not print.
  • Quotes must match. Start and end text with the same kind of quote mark.
  • Brackets must close. Every ( needs a ).
  • Typos. Read the error message: Python tells you the line number where it got confused.

Errors are normal. Even experienced programmers see them every day. Read the message, fix the line, run again.

Try it yourself

  1. Print your own name on one line and your school or city on the next.
  2. Add a comment above them explaining what the program does.
  3. Break something on purpose (remove a closing quote) and read the error message.

Next lesson: storing information in variables.

Finished this lesson?Log in to save your progress and pick up where you left off.
Next lesson →

Comments

Loading comments…

MeroSir Team
A free MeroSir course. Run the examples yourself and try the exercises: you learn programming by doing. Spotted a mistake? Use the Report button above the lesson.
Lesson 1: Meet Python and Write Your First Program | MeroSir