DEV Community

tamilvanan
tamilvanan

Posted on

Learn Python 002

Note: I’m not an expert. I’m writing this blog just to document my learning journey. 🚀


🧠 What is Python?

Python is a programming language. But what does that really mean?

✅ First Principles:

A programming language is a system of precise instructions we give to computers so they can solve problems automatically.

Python was designed to make this system of instructions:

  • Simple to read
  • Easy to write
  • Powerful enough to solve real problems

🪜 Step-by-Step Python Basics (Ground-Up)


1. 🖨️ print() — The First Tool

✅ What is it?

print() tells the computer to display something — it’s your first way to talk back to the user (or yourself).

print("Hello, world!")
Enter fullscreen mode Exit fullscreen mode

🧠 Why it matters:

  • Programming is invisible — the computer won’t tell you what it’s thinking.
  • print() helps you see what’s happening in your code.
  • It's like debugging with a flashlight.

2. 🧺 Variables — Naming Your Data

✅ What is a variable?

A variable is a name for a piece of data.

name = "Alice"
age = 25
Enter fullscreen mode Exit fullscreen mode
  • name is a label
  • "Alice" is a string
  • age is a label for the number 25

🧠 Why it matters:

You can’t solve problems if you can’t remember things.
Variables are how a program stores memory.


3. 🧠 Data Types — What Kinds of Data Can We Use?

Type Example What it Represents
int 10 Whole numbers
float 3.14 Decimal numbers
str "Hello" Text (string of characters)
bool True/False Logical values
list [1, 2, 3] Sequence of values
dict {"a": 1} Key-value pairs

🧠 Why it matters:

Each data type tells Python what kind of operations it can do:

  • int and float can be added/subtracted
  • str can be joined ("Hello" + " World")
  • list and dict can be looped over, indexed, and changed

4. 🔁 Control Flow — Making Decisions

✅ Problem: How do we tell Python to choose?

age = 17

if age >= 18:
    print("You are an adult.")
else:
    print("You are a minor.")
Enter fullscreen mode Exit fullscreen mode

🧠 Why it matters:

Programming is not linear.
You need to say “Do this only if that is true.”

Control flow gives you:

  • if: run if condition is true
  • else: run if not
  • elif: try another condition if the first fails

5. 🔂 Loops — Doing Something Repeatedly

✅ Problem: I want to do the same task many times

for i in range(5):
    print(i)
Enter fullscreen mode Exit fullscreen mode
  • range(5) means: 0, 1, 2, 3, 4
  • i is the variable that changes each time
  • print(i) happens once per loop

🧠 Why it matters:

Computers are good at repetition.
Don’t repeat yourself — loop instead.


6. 🧪 Input — Talk to the User

name = input("What is your name? ")
print("Hello,", name)
Enter fullscreen mode Exit fullscreen mode
  • input() pauses and waits for the user to type
  • The result is always a str

🧠 Why it matters:

Good programs are interactive.
Input lets your code respond to human action.


7. 🧮 Real-World Program Example

Convert Celsius to Fahrenheit

c = float(input("Enter temperature in Celsius: "))
f = (c * 9 / 5) + 32
print("Fahrenheit:", f)
Enter fullscreen mode Exit fullscreen mode

This uses:

  • Input
  • Type conversion (float)
  • Math
  • Output

🧠 Why it matters:

Programming turns formulas into tools.


8. 🧱 Functions — Reusable Logic

def greet(name):
    print("Hello,", name)

greet("Alice")
greet("Bob")
Enter fullscreen mode Exit fullscreen mode
  • def creates a new function
  • greet() calls it

🧠 Why it matters:

Repetition is wasteful.
If a task happens often, turn it into a function.


✅ Summary: What You Now Know

Concept What It Solves
print() See what your program is doing
Variables Store data with a name
Data Types Work with different kinds of values
if/else Make decisions
for loops Repeat actions
input() Get user input
Functions Reuse logic

Top comments (0)