DEV Community

Fidel Okumu
Fidel Okumu

Posted on

Python Basics: Variables, Data Types

** Introduction**
Before writing any meaningful program, I had to understand the four building blocks of Python: variables, data types, input/output, and basic syntax. This article walks through what each of these means, how they work, and practical examples of using them.

Variables
A variable is a named container that holds a value. Instead of typing "Amina" every time I refer to a driver, I can store it once:

Once created, a variable's value can be reassigned at any point:

What I understood here is that a variable isn't the value itself , it's a label pointing to a value stored in memory. Reassigning it just moves the label to point somewhere else.

Data Types
Python automatically figures out the "type" of data a variable holds. The core types I worked with:

I can check any variable's type using the built-in type() function:

Input and Output
print() is how a Python program communicates back to the user, it's the "output".

Input() -it pauses the program and waits for the user to type something:

One important detail I learned: everything input() receives is treated as text (a string), even if the user types a number. So if I need to do math with it, I have to convert it explicitly:

What I Learned
The biggest shift in understanding was realizing that a variable's type isn't fixed by how it looks on screen , input() always hands back text, and it's my job to convert it to the right type before using it in calculations. This became a recurring theme as I moved into working with real project data, where columns coming from a database or CSV often needed the same kind of type checking before I could analyze them.

Top comments (0)