Article · 24 SEPT 2026 · 6 min · Hariom Lohar

Python Basics: Variables & Data Types

By Hariom Lohar (hariomlohardev) · 1012 words · committed in public

👋 Introduction

Hi, I'm Hariom Lohar. I'm currently learning AI, with the long-term goal of moving into AGI Safety. Right now, I'm on a personal challenge, and as part of it, I'm helping others (like you!) learn programming and AI fundamentals from scratch.

This blog post is part of a series where we go from the absolute basics to advanced concepts, step by step. Today's topic: Variables and Data Types in Python — one of the very first building blocks you need before you can write any real program.


🎥 Watch the Video First

Before reading further, watch this video. It covers the core basics of variables and data types in Python:

👉 Python Variables for Beginners – Bro Code

⚠️ Important: After watching the video, make sure to read the rest of this blog post. The video covers the core basics, but it does not include everything (like Type Checking and User Input), which are explained in detail below. Reading the full post will fill those gaps and make sure your understanding is complete.

📖 What You'll Learn in This Post

  • What a variable is
  • The core data types in Python
  • How to check a variable's data type
  • How to convert one data type into another
  • How to take input from a user
  • Frequently Asked Questions (FAQs)
  • A practice Python file to test yourself

🔤 What is a Variable?

A variable is simply a named container used to store data/information, so that it can be used later in your program.

name = "Hariom"
age = 21

Here, name and age are variables. Python doesn't require you to mention the data type while creating a variable — it figures that out automatically based on the value you assign.


🔢 Core Data Types in Python

int — Integer Whole numbers, with no decimal point.

age = 21

float — Floating Point Number Numbers that include a decimal point.

price = 99.99

str — String Text, written inside single ' ' or double " " quotes.

name = "Hariom"

bool — Boolean Can only be one of two values: True or False. Mostly used for conditions and comparisons.

is_learning = True

🔍 Type Checking (Not Covered in the Video)

The video does not cover this part, so pay close attention here.

Python has a built-in function called type() that tells you the data type of any variable.

x = 10
print(type(x))   # Output: <class 'int'>

This is useful when you're not sure what type of data a variable is holding — especially when working with user input or data from external sources.


🔄 Type Conversion (Casting)

Sometimes the data you have is in one type, but you need it in another type to actually use it properly. Converting one data type into another like this is called Type Conversion, also known as Casting.

Why does this matter? If you take a number from the user using input(), Python stores it as a string (text), even if the user typed "25". If you try to do math on it directly, Python will throw an error — because you can't add a number to text. To fix this, you must convert that string into an integer or float first.

Common conversion functions:

int() — Converts a value into an integer

int("5")   # → 5

float() — Converts a value into a float

float("5")   # → 5.0

str() — Converts a value into a string

str(5)   # → "5"

bool() — Converts a value into a boolean

bool(1)   # → True

Example:

num_str = "5"             # this is a string, not a number
num_int = int(num_str)    # now it's an actual integer: 5
print(num_int + 10)       # Output: 15 — this works now!

⌨️ Taking User Input (Not Covered in the Video)

The video does not cover this part either, so read carefully.

The input() function is used to take input directly from the user while the program is running.

user_name = input("Enter your name: ")

Important: input() always returns a string, even if the user types a number. So if you need to use that input as a number, you must convert it using int() or float() (see the Type Conversion section above).


❓ FAQs

Q1. Do I need to tell Python what data type a variable is? No. Python automatically detects the data type based on the value you assign.

Q2. Can a variable's data type change later in the program? Yes. Python variables are dynamically typed, meaning you can reassign a variable to a different type at any time.

Q3. Why does input() always give a string? Because Python doesn't know if you intended to type a number or text — treating everything as a string by default is the safest option, and it's up to you to convert it if needed.

Q4. What does type(True) return? It returns <class 'bool'>, since True and False belong to the boolean data type.

Q5. What happens if I try to add a string and a number without converting? Python will raise a TypeError, since it cannot combine incompatible data types directly.


🐍 Practice File — Test Yourself

Now that you've watched the video and read through this post, it's time to test what you've actually understood.

Download the practice Python file below. It has guided comments and blank spaces — you need to write the code yourself.

👉 Download the Practice File Here

Once done, submit your completed file in the comment section of this blog post. I'll personally review it and give you feedback.


✅ Deadline Reminder

This task/assignment should be completed within 2 days — by Saturday, September 26, 2026, 11:00 AM UTC. If you get stuck anywhere, don't hesitate to ask in the group — we're all learning together. 🙌

Rate this log tap a star · smooth
thanks for rating
Discuss — replies · rating 0 comments
cookie hl_cid · name saved after first comment
Share — Lab Notebook №01
← Back to blog Follow on GitHub ↗