Sitemap

Python for Beginners: Variables, Data Types, and Why They’ll Change Everything

9 min readOct 29, 2025

--

Let’s write real code together and understand the building blocks of every program you’ll ever create.

Press enter or click to view image in full size
Photo by Mohammad Rahmani on Unsplash

This is purely intended for beginners who are yet to dip their feet into the deep waters of Python. By the end of this post, you’ll have:

✅ Written and run your first interactive Python program

✅ Mastered the four fundamental data types that power everything

✅ Built a working calculator from scratch

✅ Understood why variables are your code’s superpower

No theory overload. No boring lectures. Just you, your computer, and the rush of creating something that actually works. Sound exciting? Let’s dive in!

Setting Up Your Python Playground

Step 1: Download Python

  1. Go to python.org
  2. Click the big yellow “Download Python” button
  3. Run the installer
  4. IMPORTANT: Check the box that says “Add Python to PATH” before clicking Install

Step 2: Choose Your Code Editor

You can write Python in any text editor, but I recommend starting with one of these:

  • VS Code (my personal favorite — free, powerful, beginner-friendly)
  • PyCharm Community Edition (specifically built for Python)
  • Python IDLE (comes with Python, perfect for absolute beginners)

For this tutorial, I’ll use VS Code, but everything works the same regardless of your choice.

Step 3: Write Your First Line of Code

Open your code editor, create a new file called hello.py, and type this:

print("Hello, World!")
# Output: Hello, World!

Now run it. In VS Code, you can press the play button in the top right, or open the terminal and type:

python hello.py

Did you see “Hello, World!” appear on your screen?

Congratulations. You’re officially a Python programmer.

I know it seems simple. But you just wrote a program that communicated with your computer, told it to do something, and it obeyed. That’s powerful.

But wait — what just happened there? You used your first Python function: print()

Meet Your First Function: print()

Think of functions as pre-built tools that perform specific tasks. The print() function is one of the most important tools in your Python toolkit—it displays text on your screen.

print("Programming is fun!")
print("You can print anything you want!")
print("Numbers work too:", 42)
# Output: Programming is fun!
# Output: You can print anything you want!
# Output: Numbers work too: 42

The print() function takes whatever you put inside the parentheses and shows it to the user. It's how your programs communicate with the world.

Understanding Variables: Your Code’s Memory

“Variables let your programs remember information and use it later. Without variables, every program would be completely static.”

What is a Variable?

Think of a variable as a labeled box where you can store information. That’s literally it.

You give the box a name, put something inside it, and Python remembers what you stored there.

Let me show you:

name = "Peter"
age = 23
is_student = True

Here, I created three variables:

  • name stores the text "Peter"
  • age stores the number 23
  • is_student stores a True/False value

Variables let your programs remember information and use it later. Without variables, every program would be completely static — it couldn’t adapt, remember, or respond to different inputs.

Variable Naming Rules (The Only Rules You Need to Know)

Python is pretty relaxed about variable names, but there are a few rules:

You CAN:

  • Use letters, numbers, and underscores: user_name, age2, total_score
  • Start with letters or underscores: _private, name
  • Use descriptive names: student_grade is better than sg

You CANNOT:

  • Start with numbers: 2users ❌
  • Use spaces: user name ❌
  • Use special characters: user@name ❌
  • Use Python keywords: print, if, for ❌

Pro tip: Use descriptive names that make your code self-documenting. Future you will thank present you.

# Bad (but technically works)
x = 25
y = 30
z = x + y

# Good (self-explanatory)
hours_worked = 25
hourly_rate = 30
total_payment = hours_worked * hourly_rate

See the difference? The second version tells you exactly what’s happening without needing comments.

Press enter or click to view image in full size

Data Types: The Different Flavors of Information

Not all information is the same. A person’s name is different from their age, which is different from whether they’re a student or not. Python recognizes these differences through data types.

Let’s explore the four fundamental data types you’ll use constantly.

1. Strings (Text)

Strings are sequences of characters — basically any text. You create them by wrapping text in quotes (single or double, Python doesn’t care).

first_name = "Peter"
last_name = 'Parker' # Single quotes work too
full_message = "Welcome to Python programming!"

String Operations with Our Toolkit Functions:

Get Ajay Narayan’s stories in your inbox

Join Medium for free to get updates from this writer.

But first, let me introduce you to a powerful function: len().

Meet len(): The Length Detective

The len() function counts how many characters are in a string (or items in other data types). Think of it as your character counter.

# Concatenation (joining strings)
greeting = "Hello, " + "World!"
print(greeting) # Output: Hello, World!

# Repetition
laugh = "ha" * 3
print(laugh) # Output: hahaha

# Getting string length with len()
message = "Python is awesome"
length = len(message)
print(f"The message '{message}' has {length} characters")

Real-world use: Storing names, addresses, email content, website URLs — basically any text information.

2. Integers (Whole Numbers)

Integers are whole numbers without decimal points — positive, negative, or zero.

age = 25
temperature = -5
score = 0
population = 8000000

Integer Operations:

# Basic math
x = 10
y = 3

addition = x + y # 13
subtraction = x - y # 7
multiplication = x * y # 30
division = x / y # 3.333...
floor_division = x // y # 3 (rounds down)
modulo = x % y # 1 (remainder)
exponent = x ** y # 1000 (10 cubed)

print(f"Addition: {x} + {y} = {addition}")
print(f"Division: {x} / {y} = {division}")

Real-world use: Counting items, tracking ages, calculating scores, measuring quantities.

3. Floats (Decimal Numbers)

Floats are numbers with decimal points. Python calls them “floating-point numbers.”

price = 19.99
temperature = 98.6
pi = 3.14159
percentage = 0.85

Meet round(): The Precision Master

The round() function helps you control how many decimal places you want to display. It's essential for working with money and measurements.

# Math with floats
cost = 29.99
tax_rate = 0.08
total = cost + (cost * tax_rate)
print(f"Raw total: {total}") # Output: 32.3892

# Using round() to clean it up
clean_total = round(total, 2) # Round to 2 decimal places
print(f"Clean total: ${clean_total}") # Output: $32.39

Real-world use: Money calculations, scientific measurements, percentages, GPS coordinates.

4. Booleans (True or False)

Booleans represent one of two values: True or False. They're fundamental to making decisions in code.

is_logged_in = True
has_permission = False
is_raining = True
game_over = False

Boolean Operations:

# Comparisons return booleans
age = 25
is_adult = age >= 18 # True
is_teenager = age < 20 # False

print(f"Is adult? {is_adult}")
print(f"Is teenager? {is_teenager}")

# Logical operations
has_ticket = True
has_id = True
can_enter = has_ticket and has_id # True

is_weekend = False
is_holiday = False
need_work = not (is_weekend or is_holiday) # True

print(f"Can enter venue? {can_enter}")
print(f"Need to work? {need_work}")

Real-world use: User authentication, permission checks, game states, validation logic.

This is just for lesson one. There’s plenty more data types for us to explore further in upcoming posts. Until then, let’s get our hands dirty with these four.

Type Checking and Conversion

Sometimes you need to know what type of data you’re working with, or convert between types.

Meet type(): The Data Detective

The type() function tells you exactly what kind of data you're dealing with. It's like having X-ray vision for your variables.

name = "Alice"
age = 30
height = 5.6
is_student = False

print(f"name is type: {type(name)}") # <class 'str'>
print(f"age is type: {type(age)}") # <class 'int'>
print(f"height is type: {type(height)}") # <class 'float'>
print(f"is_student is type: {type(is_student)}") # <class 'bool'>

Meet the Conversion Squad: int(), float(), str()

These functions transform data from one type to another. They’re your data transformers.

  • int(): Converts to whole numbers
  • float(): Converts to decimal numbers
  • str(): Converts to text
# String to Integer using int()
age_text = "25"
age_number = int(age_text)
print(f"Next year you'll be: {age_number + 1}") # Output: 26

# Integer to String using str()
score = 100
message = "Your score is: " + str(score)
print(message) # Output: Your score is: 100

# String to Float using float()
price_text = "19.99"
price_number = float(price_text)
print(f"Double price: ${price_number * 2}") # Output: $39.98

# Float to Integer using int() (loses decimal part)
exact_price = 19.99
rounded_price = int(exact_price)
print(f"Rounded price: ${rounded_price}") # Output: $19

Common Beginner Mistake:

# This will cause an error
age = "25"
next_year = age + 1 # ❌ TypeError: can't add string and integer

# This is the correct way
age = "25"
next_year = int(age) + 1 # ✅ Works! Result: 26

Getting Input From Users

Static programs are boring. Let’s make your programs interactive by getting input from users.

Meet input(): The Conversation Starter

The input() function pauses your program and waits for the user to type something. It's how you make your programs interactive and personal.

# Getting user input with input()
name = input("What is your name? ")
print(f"Hello, {name}! Welcome to Python!")

# Input is always a string, so convert if needed
age_text = input("How old are you? ")
age = int(age_text) # Convert to integer
next_year_age = age + 1
print(f"Next year you'll be {next_year_age}!")

When you run this, the program will pause and wait for the user to type something. That’s the magic of input().

Your First Real Program: Simple Calculator

Let’s put everything together and build something useful — a calculator that takes two numbers and performs basic operations.

# Simple Calculator Program
print("=== Simple Calculator ===")
print("Welcome! Let's do some math together.")
print()

# Get input from user using input()
print("First, let's get your numbers...")
num1_text = input("Enter first number: ")
num2_text = input("Enter second number: ")

# Convert to numbers using float()
num1 = float(num1_text)
num2 = float(num2_text)

# Perform calculations
addition = num1 + num2
subtraction = num1 - num2
multiplication = num1 * num2
division = num1 / num2

# Display results using print() and f-strings
print()
print("=== Results ===")
print(f"{num1} + {num2} = {addition}")
print(f"{num1} - {num2} = {subtraction}")
print(f"{num1} × {num2} = {multiplication}")
print(f"{num1} ÷ {num2} = {round(division, 2)}") # Using round() for clean division

Try running this program! Enter different numbers and see what happens. You just built a functional calculator using all the functions we learned:

  • print() for output
  • input() for getting user data
  • float() for converting text to numbers
  • round() for clean decimal display

String Formatting: Making Output Look Professional

Notice those f"..." strings in the calculator? That's called f-string formatting, and it's the modern way to create formatted output in Python.

name = "Peter"
age = 28
city = "New York"

# Old way (still works but verbose)
message = "My name is " + name + ", I'm " + str(age) + " years old, and I live in " + city
print(message)

# New way (much cleaner with f-strings)
message = f"My name is {name}, I'm {age} years old, and I live in {city}"
print(message)

# You can even do calculations inside f-strings
price = 19.99
quantity = 3
print(f"Total cost: ${price * quantity}") # Output: Total cost: $59.97

F-strings make your output more readable and your code cleaner. Use them everywhere!

Common Beginner Mistakes (And How to Avoid Them)

Here are a few common mistakes that are bound to happen when we start. After all, we learn from our mistakes, right?

1. Forgetting to Convert Input

# Wrong
age = input("Enter age: ")
future_age = age + 10 # ❌ Error! Can't add string and integer

# Right
age = int(input("Enter age: "))
future_age = age + 10 # ✅ Works!

2. Using the Wrong Quote Type in Strings

# Wrong
message = "It's a beautiful day" # ❌ Error! Apostrophe breaks the string

# Right
message = "It's a beautiful day" # ✅ Escape the apostrophe
# or
message = 'It\'s a beautiful day' # ✅ Use single quotes outside

3. Mixing Up Data Types in Operations

# Wrong
result = "5" + 5 # ❌ Can't add string and integer

# Right
result = int("5") + 5 # ✅ Convert to integer first
# or
result = "5" + str(5) # ✅ Convert to string first

4. Case Sensitivity

name = "Alice"
print(Name) # ❌ NameError: name 'Name' is not defined
print(name) # ✅ Works!

Python is case-sensitive. name, Name, and NAME are three different variables.

Your Practice Challenge

Here’s a challenge for you before our next post:

Build an “About Me” program that:

  1. Asks for your name, age, and favorite hobby using input()
  2. Calculates how old you’ll be in 10 years using math
  3. Uses len() to count the characters in your hobby
  4. Displays a message like: “Hi, I’m [name]. I’m [age] years old and I love [hobby] (that’s [length] characters long!). In 10 years, I’ll be [future age]!”

Don’t forget to share your solution in the comments!

Remember: every expert was once a beginner who didn’t give up. You’ve got this.

See you in the next post! 🐍✨

Want to accelerate your Python journey? Follow for daily Python tips, tricks, and real-world projects that will make you a confident programmer.

--

--

Ajay Narayan
Ajay Narayan