0
0
Pythonprogramming~5 mins

Variable assignment in Python

Choose your learning style9 modes available
Introduction

Variable assignment lets you store information to use later in your program. It helps keep track of values like numbers or words.

When you want to remember a user's name after they type it.
When you need to store a number to use in calculations.
When you want to save a message to show on the screen.
When you want to keep track of a score in a game.
When you want to hold temporary data while your program runs.
Syntax
Python
variable_name = value

The = sign means 'store this value in the variable'.

Variable names should start with a letter or underscore and have no spaces.

Examples
This stores the word "Alice" in the variable called name.
Python
name = "Alice"
This stores the number 30 in the variable called age.
Python
age = 30
This stores a decimal number (float) 23.5 in temperature.
Python
temperature = 23.5
This stores a True/False value in is_raining.
Python
is_raining = False
Sample Program

This program saves a name and age, then prints them out.

Python
name = "Bob"
age = 25
print(f"Name: {name}")
print(f"Age: {age}")
OutputSuccess
Important Notes

You can change a variable's value anytime by assigning a new value.

Variable names are case sensitive: Age and age are different.

Use meaningful names to make your code easier to understand.

Summary

Variable assignment stores values to use later.

Use = to assign values to variables.

Choose clear names and remember variables can change.