Skip to content
Lesson 1 of 10 · Python for Complete Beginners

Your first program

Run a program, print text and numbers, and tell a string from a number.

14 min

A program is a list of instructions the computer follows from the top, one line at a time. Python reads your lines in order, does what each one says, and stops at the end.

The instruction you will use most is print(). It shows something on the screen:

python2 lines
print("Hello, world!")
print(2 + 3)

The first line prints the text Hello, world!. The second prints 5: Python worked out the sum first, then printed the answer.

Everything in Python is a value, and every value has a type. Four types cover most of what you will do this month:

TypeWhat it holdsExample
intwhole numbers7, -3, 0
floatnumbers with a decimal point2.5, 0.1
strtext (a string)"hello", '42'
booltrue or falseTrue, False

Text goes inside quotes, single or double, and they must match. Without quotes Python thinks a word is a name and complains that it does not know it.

You can ask for a value's type with type(): print(type(3.0)) shows <class 'float'>.

A # starts a comment. Python ignores the rest of that line. Use comments to tell a human reader why, not to repeat what the code says.

Common misconception

“"5" and 5 are the same thing, because they look the same.”

On screen both print as a 5, and in everyday life a digit is a digit.

What is actually true

5 is an int you can do sums with. "5" is text that happens to contain the character 5. 5 + 5 is 10, but "5" + "5" is "55": for text, + glues pieces together.

How to catch yourself

When a result looks like glued digits ("55", "1010"), one of your values is a str.

Exercise1 case
python

Write a program that prints exactly these two lines, one under the other:

code2 lines
Hello, world!
I am learning Python.

Use two print() calls.

Your code must satisfy

  • prints both lines
starter code1 line
# Your two print() calls go here
Exercise1 case
python

print() can take several values separated by commas and puts a space between them. Print one line that says the type of the value 3.0, in this form:

code1 line
3.0 is <class 'float'>

Do not type the word float yourself: let type() produce it.

Your code must satisfy

  • type printed
starter code1 line
print(3.0, 'is', )
  • A program is a list of instructions Python follows from the top, in order.
  • print() shows a value; # starts a comment Python ignores.
  • The four everyday types are int, float, str and bool.
  • Quotes make text: "5" is a string and 5 is a number, and they behave differently.
Check yourself

Check the ideas before you move on.

1Multiple choice

What does print(2 + 3) show?

  • A2 + 3
  • B5
  • C23
  • DAn error
2Multiple choice

Which value is a str?

  • A`42`
  • B`4.2`
  • C`"42"`
  • D`True`
3Multiple choice

What does print("5" + "5") show?

  • A10
  • B55
  • C5 5
  • DAn error
4Fill the blanks

A line that starts with is a comment, and Python ignores it.

Capitalisation, spacing and punctuation are ignored when grading.

5Select all that apply

Which of these are valid Python values?

  • A`3.14`
  • B`"hello"`
  • C`hello`
  • D`False`
For you · never graded

Think of one small task you do every day, such as making tea. Write it as a list of exact steps a robot could follow. Where did you have to be more precise than you expected?

Practise this lesson, not just read it

In BiliMind the questions above are marked when you answer, the flashcards come back on a schedule, and the rest of Python for Complete Beginners is planned around your week. Free.