👋 Work With Me

I help startups and teams build production-ready apps with Django, Flask, and FastAPI.

Let’s Talk →

I'm always excited to take on new projects and collaborate with innovative minds.

Address

No 7 Street E, Federal Low-cost Housing Estate, Kuje, Abuja 903101, Federal Capital Territory

Social Links

Tutorials

Python Tutorial Series – Lesson 2: Variables & Data Types

Python Tutorial for Beginners (Lesson 2): Learn Python variables and data types with examples, screenshots, and exercises for absolute beginners.

Python Tutorial Series – Lesson 2: Variables & Data Types

Welcome back to the Python Tutorial Series for Beginners! 🎉

In Lesson 1, we installed Python, set up VS Code, and ran our first program.
Now in Lesson 2, we’ll learn one of the most important concepts in programming: Variables & Data Types.

By the end of this lesson, you’ll know how to:

  • Create and use variables in Python
  • Understand Python’s built-in data types (strings, integers, floats, booleans)
  • Combine them in simple programs

🔹 What is a Variable?

A variable is like a container that stores data in your program.
Think of it as a box with a label on it. You put a value inside, and you can use it later.

Example:

 
name = "Kingsley"
age = 25

Here,

  • name is a variable storing a string "Kingsley"
  • age is a variable storing an integer 25

VS Code showing variables name and age defined
 


🔹 Rules for Naming Variables

  1. Names must start with a letter or underscore (_)
  2. Names cannot start with a number
  3. No spaces (use underscores _ instead)
  4. Variable names are case-sensitive (Age and age are different)
  5. Use descriptive names for clarity

✅ Good examples:

 
user_name = "Alice"
user_age = 30

❌ Bad examples:

 
1user = "Alice"     # starts with a number
user-name = "Bob"   # hyphens not allowed

🔹 Data Types in Python

Python automatically understands the type of data stored in a variable. The common types are:

Data TypeExampleUsage
String (str)"Hello World"Text data
Integer (int)25Whole numbers
Float (float)3.14Decimal numbers
Boolean (bool)True / FalseLogic values

1. String (str) – Text inside quotes

 
greeting = "Hello, World!"

2. Integer (int) – Whole numbers

 
age = 25 

3. Float (float) – Decimal numbers

 
price = 19.99 

4. Boolean (bool) – True or False

 
is_student = True 

VS Code showing examples of all 4 data types
 


🔹 Checking Data Types

You can use the built-in type() function to check what type a variable is:

 
x = "Hello"
y = 10
z = 3.14
flag = False
print(type(x))  # <class 'str'>
print(type(y))  # <class 'int'>
print(type(z))  # <class 'float'>
print(type(flag))  # <class 'bool'>

Terminal showing type outputs
 


🔹 Changing Values

You can reassign variables at any time:

 
name = "Kingsley"
print(name)   # Kingsley
name = "John"
print(name)   # John

🔹 Exercises for Beginners

Try these in your Python file (lesson2.py):

  1. Create a variable city and store your city’s name.
  2. Create two variables x = 5 and y = 3. Print their sum.
  3. Store your age in a variable and print:

     
    print("I am", age, "years old") 
  4. Challenge: Create variables for a product: product_name, price, and in_stock. Print them in a single line like:

     
    Product: Laptop | Price: 350000 | Available: True 

🎯 Recap

In this lesson, you learned:
✅ What variables are and how to create them
✅ Rules for naming variables in Python
✅ Python’s main data types (string, integer, float, boolean)
✅ How to check and update variable values

Next up: Lesson 3 – Operators in Python (arithmetic, comparison, and logical operators). 🚀

💼 Need a Developer?

I'm Kingsley Odume, a Django, Flask, and FastAPI developer with experience building SaaS platforms, APIs, and modern web apps. If you're a recruiter or business owner looking for a reliable software developer, let's connect!

🚀 Hire Me

Python tutorials, Python, Python Beginners series, Python Step-byStep
3 min read
Aug 20, 2025
By Kingsley Odume
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Aug 29, 2025 • 3 min read
Step-by-Step: Building a SaaS App with Django + Stripe Payments

Learn how to build a real-world SaaS app with Django and Stripe paymen...

Aug 21, 2025 • 3 min read
Final Wrap-Up: Python Tutorial Series for Beginners

Congratulations on completing the Python Tutorial Series! 🚀 In this w...

Aug 20, 2025 • 4 min read
Final Lesson: Mini Project – Putting It All Together in Python

In this final lesson, we’ll bring all those concepts together in a Min...

Your experience on this site will be improved by allowing cookies. Cookie Policy