Ch1. Python Fundamentals — Setup, Syntax & Your First Program
Why Python?
Python is the world’s most popular programming language (TIOBE Index #1, 2024).
Why Python wins:
- Readable, English-like syntax that’s beginner-friendly
- Massive library ecosystem (data science, AI/ML, web, automation)
- Fast development cycle (interpreted language)
- The de facto standard for data science and AI/ML
Installation
Option 1: Anaconda (recommended for beginners)
- Download Anaconda at anaconda.com
- Launch Jupyter Notebook after installation
- Comes with all major data science libraries pre-installed
Option 2: Python + VS Code
- Download Python 3.x from python.org
- Install VS Code + Python extension
- Verify with
python --versionin terminal
Basic Data Types
# Integer
age = 25
count = -3
# Float
pi = 3.14159
temperature = -2.5
# String
name = "Alice"
greeting = 'Hello, World!'
# Boolean
is_student = True
is_raining = False
# Check types
print(type(age)) # <class 'int'>
print(type(pi)) # <class 'float'>
print(type(name)) # <class 'str'>
Operators
# Arithmetic
print(10 + 3) # 13
print(10 - 3) # 7
print(10 * 3) # 30
print(10 / 3) # 3.333...
print(10 // 3) # 3 (floor division)
print(10 % 3) # 1 (modulo)
print(10 ** 2) # 100 (exponentiation)
# Comparison
print(5 > 3) # True
print(5 == 5) # True
print(5 != 4) # True
# Logical
print(True and False) # False
print(True or False) # True
print(not True) # False
Conditionals
score = 85
if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 70:
print("C")
else:
print("F")
# Output: B
Loops
# for loop
for i in range(5):
print(i, end=" ") # 0 1 2 3 4
# while loop
count = 0
while count < 3:
print(f"Count: {count}")
count += 1
# Iterate over a list
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
First Program: Temperature Converter
def celsius_to_fahrenheit(celsius):
fahrenheit = (celsius * 9/5) + 32
return fahrenheit
temp_c = float(input("Enter temperature in Celsius: "))
temp_f = celsius_to_fahrenheit(temp_c)
print(f"{temp_c}°C = {temp_f:.1f}°F")
Chapter 2 Preview
Next: Python Data Structures — lists, dictionaries, tuples, sets, and list comprehensions.
O
OIYO Editorial
Editorial DeskThe OIYO editorial desk researches money, law, lifestyle, and self-understanding topics against primary sources and public statistics. Every piece carries source notes and is reviewed on a regular cycle for accuracy and usefulness.