Module 2: Python FundamentalsBeginner15 min read
Variables & Data Types
Explore integers, floats, booleans, strings, and dynamic typing in Python.
Key Takeaways & Core Concepts
- Must begin with a letter or underscore
_. - Cannot start with a number.
- Can only contain alphanumeric characters and underscores (
A-z,0-9, and_). - Variable names are case-sensitive (
age,Age, andAGEare three different variables).
Variables & Data Types
### Python Variables & Data Types
Variables are containers for storing data values. In Python, a variable is created the moment you first assign a value to it using the assignment operator =.
PYTHON Code Example
1age = 25 # int
2price = 19.99 # float
3name = "Alex" # str
4is_enrolled = True # bool
5nothing = None # NoneType
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
5 lines
#### Checking Types with type() You can inspect the runtime type of any variable using Python's built-in type() function:
PYTHON Code Example
1x = 42
2print(type(x)) # <class 'int'>
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
2 lines
#### Variable Naming Rules:
- Must begin with a letter or underscore
_. - Cannot start with a number.
- Can only contain alphanumeric characters and underscores (
A-z,0-9, and_). - Variable names are case-sensitive (
age,Age, andAGEare three different variables). - Cannot use Python reserved keywords (such as
def,class,for,if,return).
Multiple Variable Assignment
1name, role, experience_years = "Priya", "Full Stack Dev", 4
2print(f"Developer: {name}")
3print(f"Role: {role}")
4print(f"Experience: {experience_years} years")
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
4 lines
Note: Python unpacks values on the right-hand side to variables on the left-hand side.
Practice & AssessmentPython Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)