Variables
Variables are containers for storing data values. In Python, you don't need to declare the type of a variable - Python figures it out automatically!
Creating Variables
To create a variable, simply assign a value to a name:
name = "Alice"
age = 25
height = 5.6 Variable Names
Variable names in Python must follow these rules:
- Must start with a letter or underscore (_)
- Can contain letters, numbers, and underscores
- Are case-sensitive (
nameandNameare different) - Cannot be Python keywords (like
if,for,class)
Good Variable Names
Choose descriptive names that make your code easy to understand:
user_nameinstead ofuntotal_priceinstead oftpis_validinstead ofiv
Try It
Run the code on the right to see variables in action. Try creating your own variables!
code.py
24 lines
Loading editor...
::::
Execution
Standard Output
Click "Run" to execute your Python code...