Starting with Python means learning how to store data, use text, and interact with users and that all begins with variables, strings, and input.
This post breaks these concepts down step-by-step. If you’ve never written a line of code before, don’t worry we’ll go slow, use real examples, and explain everything like I’m sitting beside you.
🧠 What Are Variables?
In Python, a variable is just a name you give to a piece of information so you can use it later.
Think of it like labeling a box.
name = "Sufiyan"
In this case:
name
is the label (the variable)"Sufiyan"
is the value inside the box (a string of text)
✅ More Examples of Variables
name = 'Ali'
score = 95
We created two variables: one holds a name, the other holds a number.
x = 10
y = x + 5
print(y)
You can create new variables based on existing ones.
is_student = True
Variables can also be booleans either
True
orFalse
.
🔤 What Is a String?
A string is just a sequence of characters letters, numbers, spaces, punctuation inside quotes.
greeting = "Hello, world!"
You can use:
- Double quotes:
"Python"
- Single quotes:
'Python'
🔁 String Examples
title = 'Python Beginner Guide'
print(title.upper())
.upper()
turns the text into ALL CAPS.
course = 'python programming'
print(course.title())
.title()
capitalizes the first letter of every word.
long_text = 'Python is easy to learn.'
print('easy' in long_text)
You can check if a word exists in a string using
in
.
📥 Getting Input from the User
Want your program to ask for someone’s name and respond?
Use the input()
function.
user_name = input("What is your name? ")
print("Nice to meet you,", user_name)
The value you get from
input()
is always a string, even if the user types a number.
✍️ More Input Examples
city = input("Which city do you live in? ")
print("Oh! I’ve heard", city, "is beautiful!")
favorite_color = input("Favorite color: ")
print(f"Nice! {favorite_color} is a cool choice.")
🔁 Combining Variables and Input
name = input("Enter your name: ")
age = input("How old are you? ")
print(f"Hello {name}! You are {age} years old.")
🔄 Type Conversion (Casting)
If you want to do math with user input, you need to convert it to a number:
birth_year = input("What year were you born? ")
age = 2025 - int(birth_year)
print(f"You are approximately {age} years old.")
🔧 More Conversion Examples
number = input("Enter a number: ")
double = int(number) * 2
print("Double:", double)
price = input("Enter price: ")
price_with_tax = float(price) * 1.18
print("Total price:", round(price_with_tax, 2))
🧪 Put It All Together
print("Welcome to the Python Quiz!")
name = input("What's your name? ")
print(f"Nice to meet you, {name}.")
language = input("Which language are you learning? ")
print(f"{language}? Great choice!")
hours = input("How many hours do you practice weekly? ")
print(f"{hours} hours is impressive! Keep going, {name}.")
⚠️ Common Mistakes to Avoid
Mistake | Fix |
---|---|
Forgetting quotes around strings | "hello" not hello |
Using variable before defining it | Define first: x = 5 → then use print(x) |
Forgetting int() when doing math | int(input(...)) instead of just input() |
Using wrong variable names | Python is case sensitive UserName ≠ username |