Course contentsLesson 1 of 13← Course overview
  1. 01Meet Python12 min
  2. 02Set up and run Python12 min
  3. 03Variables and data types15 min
  4. 04Strings and input15 min
  5. 05Decisions with conditionals15 min
  6. 06Repeat work with loops15 min
  7. 07Functions and return values18 min
  8. 08Work with lists16 min
  9. 09Dictionaries and tuples16 min
  10. 10Understand errors and exceptions14 min
  11. 11Read and write files16 min
  12. 12Modules and the standard library14 min
  13. 13Build a small data summary20 min

Python & data · Lesson 01

Meet Python

Edit lesson

Read your first Python program and see how instructions, values, and names work together.

12 minProgress saves on this device
In this lesson
  • 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.

Your first messagepython
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.

Store and display a valuepython
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.

Knowledge check

What does the name topic refer to in this example?

Try first; feedback appears after you check.
Apply it

Your turn

Change topic to something you want to learn. Write a print call that includes its value in a sentence.

Continue readingPython tutorial

BUILT TOGETHER

Help make this explanation better.

Have a clearer explanation, a useful example, or a correction? Share it with the community.

Contributors

Be the first to add your name when you improve this lesson.

How to get credited
Course overviewNext lesson