Python Variables Practice Questions for Beginners
Chapter 4 Recap and Practice
You can now store values, name them well and work with them. Here is the chapter in one table:
| You write | It means |
|---|---|
name = "Sunny" | store a value in a variable (name on the left) |
print(name) | show the value; print("name") shows the word |
total = price * qty | calculate with values, store the result |
user_name | names use letters, numbers and _, start with a letter |
age vs Age | capital letters make a different name |
class, for, if … | keywords can't be names |
score = score + 5 | a new value replaces the old one |
x = y = 0 | one value for several variables |
a, b = b, a | swap two values in one line |
str, int, float, bool | text, whole number, decimal number, True or False |
type(x) | shows the type of a value |
And remember: create a variable before you use it.
Practice questions
Write each program yourself. Use variables for the values, even when you could type the answer directly: that's the skill you're practising.
Python variables
- 16.Python Program to Create and Print a VariableEasySolve
- 21.Python Program to Add Two VariablesEasySolve
- 22.Python Program to Find the Area of a Rectangle Using VariablesMediumSolve
Naming rules
- 18.Python Program to Show That Variable Names Are Case-SensitiveEasySolve
- 33.Fix the Invalid Variable Names in a Python ProgramEasySolve
How variables work
- 19.Python Program to Assign One Value to Several VariablesEasySolve
- 20.Python Program to Reassign a VariableMediumSolve
- 24.Python Program to Swap Two Variables Without a Temporary VariableMediumSolve
- 25.Python Program to Rotate the Values of Three VariablesMediumSolve
Variable types
- 17.Python Program to Create and Print a Boolean VariableEasySolve
- 26.Python Program to Check the Type of a VariableEasySolve
- 34.Python Program to Print a Shopping Bill with VariablesHardSolve
Variables are the memory of your program. Next, you'll learn everything you can do with each type of value.