Variables and Data Types in Python
Variables in Python are used to store data. Python automatically detects the data type when a variable is assigned.
Must start with a letter or underscore.
Can contain letters, digits, and underscores.
Cannot be a Python keyword.
Python is case-sensitive (age and Age are different).
| Data Type | Description | Example |
|---|---|---|
int | Integer numbers | x = 10 |
float | Decimal numbers | y = 3.14 |
str | String (text) | name = "Python" |
bool | Boolean values | is_valid = True |
complex | Complex numbers | z = 2 + 3j |
Assign values to multiple variables in one line:
Use type() function to check the data type:
By convention, constants are uppercase:
Variables store data values for later use.
Python infers the data type automatically.
Basic data types include int, float, str, bool, and complex.
Multiple variables can be assigned in one line.
Use type() to check the data type.
Take quizzes related to this topic and see where you stand!
Start Quiz Now