Python & data · Lesson 01
Meet Python
Read your first Python program and see how instructions, values, and names work together.
- Explain what a program does
- Recognize a variable and a string
- Predict the output of print()
Helpful background: None. Start here if Python is new to you.
What is Python?
Python is a general-purpose programming language used for automation, web applications, data analysis, and many other tasks. You write instructions in a text file, and the Python interpreter executes them.
A program runs statements in order unless control flow changes that order. Start by reading a short example and predicting what each line does.
Display a message
The print() function displays values. Text surrounded by quotation marks is a string; Python prints the text without the quotation marks.
Parentheses are part of a function call. If a closing parenthesis or quotation mark is missing, Python reports a syntax error before the program can run.
print("Hello, Python!")Names make values useful
A variable name refers to a value. The equals sign assigns the value on the right to the name on the left. A name lets you reuse a value without typing it again.
Here, topic refers to a string. The f before the second string makes it an f-string: the expression inside braces is evaluated and included in the message.
topic = "city parks"
print(f"Today I am exploring {topic}.")Experiment and read errors
Change the value of topic and predict the new output before running the program. Small changes are a practical way to see how each part works.
If an error appears, read the last line of the message and check the line it points to. Errors are feedback about the program, not a sign that you cannot learn.
What does the name topic refer to in this example?
Your turn
Change topic to something you want to learn. Write a print call that includes its value in a sentence.
topic = "rivers" print(f"I want to learn about {topic}.")
BUILT TOGETHER
Help make this explanation better.
Have a clearer explanation, a useful example, or a correction? Share it with the community.
Be the first to add your name when you improve this lesson.
How to get credited