Programming fundamentalsLesson 3 of 8 in the course Statements

Python Variable Assignment, Naming, and Printing

5 flashcards · 5 quiz questions · 5 match pairs · 5 fill-in sentences · English

Lesson progress
0 / 5

Your progress is kept in this browser only.Sign up to save it

Summary

Variables let a Python program refer to values by meaningful names. This lesson explains how to assign values to variables, choose valid and readable variable names, and print variables as output.

A variable is a name that refers to a value. For example, a program might use age for a person's age or birth for a date of birth. Names help people work with values without needing to refer to where the computer stores them.

All flashcards

What is a variable?
A variable is a name that refers to a value, allowing a program to use a meaningful name instead of referring directly to a storage location.
How does Python assignment work?
The assignment operator `=` associates the value on its right with the variable on its left, as in `age = 6`.
What are the basic rules for a variable name?
A name may contain letters, digits, and underscores and can be any length, but it cannot start with a digit. Names are case-sensitive, and Python keywords are not allowed as variable names.
What is snake case?
Snake case is a naming style that uses lowercase words separated by underscores, such as `first_name` or `total_price`.
How does `print()` handle multiple comma-separated arguments?
`print()` displays each argument and separates them with spaces by default. Arguments can include both variables and text strings.

Quiz questions

  1. What does an assignment statement do in Python?Answer: It associates the value on the right side of `=` with the variable on the left side.
  2. Which variable name is invalid because of the naming rules?Answer: `101class`
  3. What is the relationship between the names `Total` and `total` in Python?Answer: They are different names because Python is case-sensitive.
  4. Why is `count` usually a better variable name than `c` in a readable program?Answer: `count` gives readers a better clue about what the variable represents.
  5. What is printed by `print(team1, "versus", team2)` when `team1 = "Liverpool"` and `team2 = "Chelsea"`?Answer: `Liverpool versus Chelsea`

Based on Introduction to Python Programming by Udayan Das, Aubrey Lawson, Chris Mayfield, Narges Norouzi (OpenStax), licensed CC BY 4.0. Adapted into a summary, flashcards and quizzes.

All Programming fundamentals lessons