CodeBlanks Logo Icon CodeBlanks

Summary - Python basics

Combine print, comments and indentation to write your first Python script.

Summary - Python basics

In this group you learned what Python is, the REPL, print, comments, indentation and running scripts.

  • Python is an interpreted, general-purpose language.
  • You print strings to the screen with print.
  • Comments start with #.
  • Indentation defines blocks; the standard is four spaces.
  • Script files use the .py extension and run with python3 file.py.

Now two small tasks combine these concepts.

Practice Write a greeting script

As if writing a hello.py script, add a # comment and below it print("Welcome"). When run, the script should print Welcome.

Starter code

main.py
# Greeting script

Sample solution

main.py
# Greeting script
print("Welcome")

Expected output

Welcome

Practice Multi-line script

Write a script with two print calls: first print Start, then End. Add a # comment at the top.

Starter code

main.py
# Two-line script

Sample solution

main.py
# Two-line script
print("Start")
print("End")

Expected output

Start
End

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is wrong?

  • print writes to the screen
  • A script uses the .txt extension Correct answer
  • Indentation defines blocks
  • # starts a comment

Explanation: Scripts use .py, not .txt.

2 Complete the indentation

Question
if True:
    ____("Blocks work")
Answer
if True:
    print("Blocks work")

Explanation: print is inside the if block.

All lessons in Beginner