๐Ÿ Python for Teens & Beginners ยท Lesson 1 of 7

Your first program

Google Classroom

print, quotation marks, and error messages.

print

print("Hello, world!")
print("My name is Sam")
print(7 + 3)

print shows something on the screen. Text goes inside quotation marks; numbers donโ€™t need them. The last line prints 10, not โ€œ7 + 3โ€.

Strings

Text in quotation marks is called a string. "Hello" and 'Hello' both work โ€” just start and end with the same kind. Without quotes, Python thinks the word is a command or a variable.

Error messages are your friends

print("Hello)
# SyntaxError: unterminated string literal

prnt("Hi")
# NameError: name 'prnt' is not defined

An error message says what went wrong and on which line. Read the last line first. Most early errors are a missing quote, a missing parenthesis or a typo.

Comments

# This is a comment. Python ignores it.
print("Comments explain your code")  # one can go here too

Tip

๐Ÿ’ก Python is case-sensitive: print works, Print does not.

โœ๏ธ Practice: your turn

  1. Print your name, your age and your favorite food on three lines
  2. Print the result of 123 * 4
  3. Make an error on purpose (remove a quote) and read the message
  4. Add a comment explaining your program

โœ๏ธ Run Python in your browser, no install โ†—

๐Ÿง  Quick quiz

Answer all 4 questions correctly to mark this lesson as done.

1. What does print("Hi") do?
2. What does print(2 + 3) show?
3. What is a string?
4. Which line has an error?

0 of 4 correct