Python Fundamentals: Everything You Need to Get Started
A clear walkthrough of Python's core building blocks — variables, data types, functions, and control flow. Practical from the first line.
Why Python First
Python is the language of data science, machine learning, and AI automation. It's also one of the most readable languages ever designed. Guido van Rossum created it with a single goal: code should read like English.
This makes Python uniquely forgiving for beginners while being powerful enough for production systems used by Google, Netflix, Instagram, and Spotify.
Variables and Types
Python is dynamically typed — you don't declare types explicitly. The interpreter figures them out.
name = "JRCodex" # str
age = 28 # int
score = 94.5 # float
is_active = True # bool
You can check any type with type():
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
Strings
Strings are sequences of characters. Python gives you a rich set of string methods:
text = " hello world "
print(text.strip()) # "hello world"
print(text.upper()) # " HELLO WORLD "
print(text.replace("hello", "hi")) # " hi world "
print(len(text)) # 15
f-strings are the cleanest way to embed variables in strings:
name = "Rahul"
score = 95.3
print(f"Student: {name}, Score: {score:.1f}%")
# Student: Rahul, Score: 95.3%
Collections
Lists
Lists are ordered, mutable sequences. Use them for things that change.
topics = ["Python", "ML", "Data Science"]
topics.append("Deep Learning") # add to end
topics.insert(0, "AI Basics") # insert at index
topics.pop() # remove last
print(topics[1]) # "Python" — zero-indexed
Slicing gives you a sub-list without loops:
print(topics[1:3]) # ['Python', 'ML']
print(topics[:2]) # first two items
print(topics[-1]) # last item
Dictionaries
Dictionaries store key-value pairs. Perfect for structured data.
student = {
"name": "Rahul",
"score": 95,
"courses": ["Python", "ML"]
}
print(student["name"]) # Rahul
print(student.get("grade", "N/A")) # N/A — safe default
student["grade"] = "A" # add new key
Control Flow
if / elif / else
score = 87
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
print(f"Grade: {grade}") # Grade: B
Loops
for loops iterate over any sequence:
topics = ["Python", "ML", "Data Science"]
for topic in topics:
print(f"Learning: {topic}")
# range() for numeric iteration
for i in range(5):
print(i) # 0, 1, 2, 3, 4
while loops run until a condition is False:
count = 0
while count < 3:
print(f"Count: {count}")
count += 1
List Comprehensions
A Python superpower — create lists in one expressive line:
numbers = [1, 2, 3, 4, 5]
# squares of all numbers
squares = [n ** 2 for n in numbers]
# [1, 4, 9, 16, 25]
# only even numbers
evens = [n for n in numbers if n % 2 == 0]
# [2, 4]
Functions
Functions let you organize code into reusable blocks.
def calculate_grade(score):
"""Return letter grade for a numeric score."""
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
return "F"
result = calculate_grade(87)
print(result) # B
Default and Keyword Arguments
def greet(name, greeting="Hello"):
return f"{greeting}, {name}!"
print(greet("Rahul")) # Hello, Rahul!
print(greet("Rahul", "Welcome")) # Welcome, Rahul!
*args and **kwargs
These let functions accept any number of arguments:
def average(*numbers):
return sum(numbers) / len(numbers)
print(average(80, 90, 95)) # 88.33...
def display_info(**details):
for key, value in details.items():
print(f"{key}: {value}")
display_info(name="Rahul", score=95, course="Python")
What to Learn Next
With these fundamentals solid, the natural next steps are:
- Object-Oriented Python — classes, inheritance, and design patterns
- File I/O — reading and writing CSV, JSON, text files
- Modules and Packages — using pip and importing libraries
- NumPy & Pandas — where Python becomes a data superpower
The goal isn't to memorize syntax. It's to build the habit of thinking in terms of data structures and transformations. Python is the vehicle — that thinking is the skill.