A Tour of Python

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 (name and Name are different)
  • Cannot be Python keywords (like if, for, class)

Good Variable Names

Choose descriptive names that make your code easy to understand:

  • user_name instead of un
  • total_price instead of tp
  • is_valid instead of iv

Try It

Run the code on the right to see variables in action. Try creating your own variables!

< 3/5 >
code.py
24 lines
Loading editor...
::::
Execution
Standard Output

Click "Run" to execute your Python code...

Table of Contents