๐ Python for Teens & Beginners ยท Lesson 1 of 7
Your first program
print, quotation marks, and error messages.
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 definedAn 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 tooTip
๐ก Python is case-sensitive: print works, Print does not.
โ๏ธ Practice: your turn
- Print your name, your age and your favorite food on three lines
- Print the result of 123 * 4
- Make an error on purpose (remove a quote) and read the message
- Add a comment explaining your program
๐ง Quick quiz
Answer all 4 questions correctly to mark this lesson as done.
0 of 4 correct
All lessons in Python for Teens & Beginners
- ๐ 1. Your first programprint, quotation marks, and error messages
- ๐ฆ 2. Variables and inputStore information and ask the user
- ๐งฎ 3. Math in PythonOperators, division, remainder and powers
- ๐ 4. Conditions: if and elseThe program decides by itself
- ๐ 5. Loops: for and whileRepeat code without copying it
- ๐ 6. ListsMany values in one variable
- ๐ฒ 7. Project: a guessing gameThe computer picks a number, and you guess