
Building on Post 1: Kickstart Your Python Journey, this part of the series takes you deeper into Python fundamentals. You’ll learn how to work with variables, understand basic data types, and perform operations that make up the backbone of Python programming.
In this tutorial, we’ll cover:
- What variables are and why they matter in programming
- Python’s core data types: integers, floats, strings, and booleans
- Assigning and updating variables
- Type conversion concepts
- Basic string operations (concatenation, slicing, formatting)
- Real-world examples tied to software development
- Practical exercises to strengthen your skills
By the end, you'll know how to store, manipulate, and display data in Python—skills you’ll use in every project, from simple scripts to enterprise apps.
1. Understanding Variables in Python
What is a Variable?
A variable is essentially a named container for storing information in your program. It lets your code store values and refer to them later.
Declaring Variables
In Python, you don’t need to explicitly declare the type of a variable—Python infers it dynamically.
Rules for naming variables:
- Must start with a letter or underscore
- Can contain letters, numbers, and underscores
- Case-sensitive (
age
andAge
are different variables) - Cannot be a Python keyword (
for
,class
,if
)
✅ Good Practice:
2. Core Data Types in Python
Python is dynamically typed, meaning you can change what type a variable holds during the program’s lifecycle.
Integers & Floats
You can perform math on them:
Strings
Strings store sequences of characters.
Basic operations:
Booleans
Booleans represent truth values, essential for conditional logic.
3. Type Conversion
Sometimes you need to change a variable’s type.
Caution: Converting incompatible types raises an error.
4. Real-World Examples
Example 1: Storing User Data
Example 2: Temperature Converter
5. Practical Exercises
Exercise 1: Write a program that:
- Stores your name, age, and city in variables
- Prints them in a formatted sentence
Exercise 2: Write a currency converter that:
- Takes USD as input
- Converts it to INR (use a hardcoded exchange rate)
Exercise 3: Experiment with slicing strings to extract parts of words.
6. Common Beginner Pitfalls
- Forgetting parentheses in
print()
calls - Mixing strings and numbers without conversion:
- Confusing
=
(assignment) with==
(comparison)
7. What’s Next
You’ve learned variables and data types—the building blocks of all programs.
Next Post: We’ll explore Control Structures—if
, for
, and while
—so you can start controlling program flow.