Python Basics · Lesson 1 of 12

Hello, Python

A program is a list of instructions that the computer carries out from top to bottom. In Python, each instruction usually sits on its own line.

Your first instruction shows a message:

print("Hello, world!")
  • print is a built-in function. It shows whatever you put in its brackets.
  • The text in quotes is called a string. The quotes mark where it starts and ends, and are not shown.

Numbers need no quotes, and Python can calculate with them:

print(42)
print(2 + 3)

print can take several things at once, separated by commas. It puts a space between them:

print("The answer is", 42)

Comments

Everything after a # on a line is a comment. Python ignores it. Comments are notes for people reading the code.

# This line does nothing
print("This line prints")

Running your code

Press Run (or Ctrl+Enter). The output appears under the editor. The very first run takes a few seconds while Python itself loads.

Python is strict about spelling and capital letters. Print with a capital P is an error. Error messages name the line, so read them: they are trying to help.

Your Task

  1. Change the first message so it prints exactly Hello, world!
  2. Add a second line that prints your name as a string.
  3. Add a third line that prints the result of 7 * 6 (use * to multiply). Let Python do the math.
  • The first line printed is Hello, world!
  • The second line printed is some text
  • The third line printed is 42, worked out by Python