Python Basics: Variables, Strings, and User Input Explained Simply

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.

Python
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

Python
name = 'Ali'
score = 95

We created two variables: one holds a name, the other holds a number.

Python
x = 10
y = x + 5
print(y)

You can create new variables based on existing ones.

Python
is_student = True

Variables can also be booleans either True or False.


🔤 What Is a String?

A string is just a sequence of characters letters, numbers, spaces, punctuation inside quotes.

Python
greeting = "Hello, world!"

You can use:

  • Double quotes: "Python"
  • Single quotes: 'Python'

🔁 String Examples

Python
title = 'Python Beginner Guide'
print(title.upper())

.upper() turns the text into ALL CAPS.

Python
course = 'python programming'
print(course.title())

.title() capitalizes the first letter of every word.

Python
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.

Python
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

Python
city = input("Which city do you live in? ")
print("Oh! I’ve heard", city, "is beautiful!")

Python
favorite_color = input("Favorite color: ")
print(f"Nice! {favorite_color} is a cool choice.")

🔁 Combining Variables and Input

Python
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:

Python
birth_year = input("What year were you born? ")
age = 2025 - int(birth_year)

print(f"You are approximately {age} years old.")

🔧 More Conversion Examples

Python
number = input("Enter a number: ")
double = int(number) * 2
print("Double:", double)

Python
price = input("Enter price: ")
price_with_tax = float(price) * 1.18
print("Total price:", round(price_with_tax, 2))

🧪 Put It All Together

Python
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

MistakeFix
Forgetting quotes around strings"hello" not hello
Using variable before defining itDefine first: x = 5 → then use print(x)
Forgetting int() when doing mathint(input(...)) instead of just input()
Using wrong variable namesPython is case sensitive UserNameusername

💌 Stay Updated with PyUniverse

Want Python and AI explained simply straight to your inbox?

Join hundreds of curious learners who get:

  • ✅ Practical Python tips & mini tutorials
  • ✅ New blog posts before anyone else
  • ✅ Downloadable cheat sheets & quick guides
  • ✅ Behind-the-scenes updates from PyUniverse

No spam. No noise. Just useful stuff that helps you grow one email at a time.

🛡️ I respect your privacy. You can unsubscribe anytime.

Leave a Comment