Wednesday, October 15, 2025

Introduction to Python

 Introduction to Python

Welcome to the world of Python! If you're new to programming or just curious, Python is one of the easiest and most powerful languages to start with. Created by Guido van Rossum in the late 1980s, Python emphasizes readability and simplicity—think of it as English-like code that lets you focus on solving problems rather than wrestling with syntax.Why Learn Python?
  • Beginner-Friendly: Clean syntax, no semicolons or curly braces needed.
  • Versatile: Used for web development (Django/Flask), data science (Pandas/NumPy), automation, AI/ML (TensorFlow), and more.
  • Huge Community: Tons of libraries, tutorials, and jobs waiting.
  • Fun and Fast: Write less code, get results quicker.
In 2025, Python remains the top language for beginners and pros alike, powering everything from Instagram's backend to NASA's data analysis.Getting Started
  1. Install Python: Download from python.org. Use version 3.12+ (avoid Python 2—it's retired).
  2. Run Code: Use the IDLE editor (comes with Python), or install VS Code for a better experience.
  3. Online Playground: Try Replit or Google Colab without installing anything.
Your First Program: Hello, World!Open a Python file (e.g., hello.py) and type:
python
print("Hello, World!")
Run it with python hello.py in your terminal. Output: Hello, World!Core ConceptsLet's build from basics. Python is interpreted (runs line-by-line) and dynamically typed (no need to declare variable types upfront).1. Variables and Data TypesVariables store data. No var or int keywords needed.
python
name = "Alice"  # String (text)
age = 30        # Integer (whole number)
height = 5.7    # Float (decimal)
is_student = True  # Boolean (True/False)

print(f"{name} is {age} years old.")  # Output: Alice is 30 years old.
Common types: str (strings), int/float (numbers), bool, list (arrays like [1, 2, 3]), dict (key-value like {"key": "value"}).2. OperatorsMath: +, -, *, /, ** (power), % (modulo).
python
x = 10
y = 3
print(x + y)  # 13
print(x ** y) # 1000
Comparisons: ==, !=, >, <, and, or.3. Control Flow: If-Else and LoopsMake decisions and repeat tasks.If-Else:
python
age = 18
if age >= 18:
    print("Adult!")
else:
    print("Minor.")
For Loop (iterate over lists):
python
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit.upper())  # APPLE, BANANA, CHERRY
While Loop:
python
count = 0
while count < 3:
    print(count)
    count += 1  # 0, 1, 2
4. FunctionsReusable code blocks. Define with def.
python
def greet(name):
    return f"Hello, {name}!"

print(greet("Bob"))  # Hello, Bob!
Add parameters, defaults, or *args for flexibility.5. Lists and DictionariesList (mutable array):
python
numbers = [1, 2, 3]
numbers.append(4)  # [1, 2, 3, 4]
print(numbers[0])  # 1 (0-indexed)
Dictionary:
python
person = {"name": "Eve", "age": 25}
print(person["name"])  # Eve
Next StepsPython's motto? "There should be one—and preferably only one—obvious way to do it." Experiment, make mistakes, and have fun. What's your first project idea? Ask me for help on specifics! 🚀

Lecture Notes: Optimising Numerical Code

Lecture Notes: Optimising Numerical Code Prerequisites: Basic Python programming Understanding of NumPy arrays and vector ...