Table of Contents
- Module 1 — Course Overview
- Module 2 — Python and Data Science
- Module 3 — Python Basics
- Module 4 — Packages and Data Structures
- Reference Diagrams
- Reference Tables
Module 1 — Course Overview
This course introduces the fundamentals of Python applied to data science. It targets beginners who want to understand the key concepts needed to start working with data in Python.
Topics covered:
- Data structures (lists, tuples, sets)
- Operators (arithmetic, comparison, logical)
- Packages and managing them with
pip - Identifiers and literals
Prerequisites: Basic understanding of what programming is.
Module 2 — Python and Data Science
What Is Python?
Python is one of the most powerful and versatile programming languages available today. Key characteristics:
- Open source — freely usable, even for commercial purposes
- Interpreted — executed line by line, not compiled as a block
- Portable — same code works on Windows, macOS and Linux
- Object-oriented — everything in Python is an object
Use cases:
- Web and desktop applications
- Automation of repetitive tasks
- Data science and machine learning
- Scripting and system administration
Python Features
| Feature | Description |
|---|---|
| Object-oriented | Everything is an object; full OOP principles support |
| Interpreted | Line-by-line execution by the Python interpreter |
| Portable | Identical code on Windows, macOS, Linux |
| Rich in libraries | Global community, thousands of packages available |
| Readable | Clear syntax close to natural language |
Python Packages for Data Science
# The major Data Science packages
import numpy # NumPy — multidimensional arrays, numerical computing
import pandas # Pandas — tabular data manipulation (DataFrames)
import matplotlib # Matplotlib — visualization and charts
import sklearn # Scikit-learn — machine learning
| Package | Main Purpose |
|---|---|
| NumPy | N-dimensional arrays, vectorized mathematical operations |
| Pandas | DataFrames, data cleaning, transformation and analysis |
| Matplotlib | Charts and visualizations (line charts, histograms, scatter plots) |
| Scikit-learn | Supervised and unsupervised machine learning algorithms |
Why Python for Data Science?
- Simplicity — readable syntax, gentle learning curve
- Rich ecosystem — NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow…
- Community — millions of developers, abundant documentation
- Jupyter Notebook — ideal interactive environment for data exploration
- Integration — easily connects to databases, APIs, and cloud tools
Installing Python
On Windows via PowerShell:
# Check if Python is already installed
python3 --version
# If Python is not found, launch installation from Microsoft Store
python3
# → Automatically opens Microsoft Store with the Python app
Post-installation verification:
python3 --version
# Output: Python 3.x.x
pip --version
# pip is included with Python 3 — no separate installation needed
Tip:
pip(Package Installer for Python) is automatically available with any recent Python 3 installation.
Python IDEs
An IDE (Integrated Development Environment) is a tool that enhances developer productivity through advanced features.
IDE advantages:
- Syntax highlighting — keywords are highlighted, code is more readable
- Autocomplete — code suggestions while typing (fewer errors, faster)
- Integrated debugging — tools for finding and fixing errors
- Git integration — version control directly in the IDE
Popular Python IDEs:
| IDE | Description |
|---|---|
| PyCharm | Professional Python-dedicated IDE (JetBrains), very comprehensive |
| Visual Studio Code | Lightweight and extensible editor, very popular in the community |
| Atom | Open source and customizable editor |
| Jupyter Notebook | Interactive environment, ideal for data science |
Installing Jupyter Notebook
Jupyter Notebook is an interactive environment that allows writing and executing Python code in cells, alongside explanatory text (Markdown). It is particularly used in data science for data exploration and visualization.
# Installation via pip
pip install jupyter
# Launch Jupyter Notebook
jupyter notebook
# → Automatically opens browser at http://localhost:8888
Basic Jupyter usage:
- Code cell — write and execute Python
- Markdown cell — write formatted text, titles, formulas
- Shift + Enter — execute current cell and move to next
- Ctrl + Enter — execute current cell without moving
Module 3 — Python Basics
Identifiers and Literals
Identifiers
An identifier is the name given to a variable, function, class, or any other Python object. Through identifiers, Python recognizes and distinguishes the different elements of a program.
Rules for identifiers:
| Rule | Valid Example | Invalid Example |
|---|---|---|
| Cannot start with a digit | name1 | 1name |
No special characters (except _) | my_var | my-var, my@var |
| No Python reserved words | my_list | list, for, if |
| Case-sensitive | Name ≠ name | — |
Python reserved keywords:
False None True and as assert async
await break class continue def del elif
else except finally for from global if
import in is lambda nonlocal not or
pass raise return try while with yield
Literals
A literal is a value directly written in the source code — a constant value.
# Numeric Literals — integers
a = 10
print(type(a)) # <class 'int'>
# Numeric Literals — floats
a = 5.2
print(type(a)) # <class 'float'>
# String Literals — double or single quotes
greeting = "Hello Python"
print(type(greeting)) # <class 'str'>
greeting = 'Hello Python' # Identical to previous
print(type(greeting)) # <class 'str'>
# Boolean Literals
a = True
print(type(a)) # <class 'bool'>
a = False
print(type(a)) # <class 'bool'>
Python literal types:
| Type | Example | Class |
|---|---|---|
| Integer | 42, -7, 0 | int |
| Float | 3.14, -0.5 | float |
| String | "hello", 'world' | str |
| Boolean | True, False | bool |
| None | None | NoneType |
Expressions and Operators
An expression is a combination of operands (values) and operators that produces a computed value.
# Expression examples
6 + 6 # → 12 (operand + operand → result)
10 - 3 # → 7
5 * 4 # → 20
print(6 + 6) # 12
print(10 - 3) # 7
print(5 * 4) # 20
Terminology: In
6 + 6, the two6s are the operands and+is the operator.
Three operator categories in Python:
- Arithmetic Operators — mathematical operations
- Comparison Operators — comparisons returning a boolean
- Logical Operators — boolean logic
Arithmetic Operators
a = 10
b = 4
print(a + b) # 14 — Addition
print(a - b) # 6 — Subtraction
print(a * b) # 40 — Multiplication
print(a / b) # 2.5 — Division (always returns float)
print(a % b) # 2 — Modulo (remainder of integer division)
print(a // b) # 2 — Floor division (rounds toward -∞)
print(a ** b) # 10000 — Exponent (10^4)
Summary table:
| Operator | Symbol | Example (a=10, b=4) | Result |
|---|---|---|---|
| Addition | + | a + b | 14 |
| Subtraction | - | a - b | 6 |
| Multiplication | * | a * b | 40 |
| Division | / | a / b | 2.5 |
| Modulo | % | a % b | 2 |
| Floor division | // | a // b | 2 |
| Exponent | ** | a ** b | 10000 |
Comparison Operators
Comparison operators compare two values and always return a boolean (True or False).
a = 10
b = 4
c = 4
print(a == b) # False — Equal to (== not =)
print(b == c) # True
print(b != c) # False — Not equal to
print(a > c) # True — Greater than
print(b < a) # True — Less than
print(b <= c) # True — Less than or equal to
print(b >= c) # True — Greater than or equal to
Important:
=is the assignment operator,==is the comparison operator.
Logical Operators
Logical operators work on boolean operands and are used in decision-making.
# Logical AND — true only if BOTH operands are True
print(True and False) # False
print(True and True) # True
# Logical OR — true if AT LEAST ONE operand is True
print(True or False) # True
print(False or False) # False
# Logical NOT — inverts the boolean value
print(not True) # False
print(not False) # True
# Using with expressions
a = 10
b = 4
c = 4
print((b >= c) and (b <= c)) # True and True → True
print((b >= c) and (a <= c)) # True and False → False
print((b >= c) or (a <= c)) # True or False → True
Truth table:
| A | B | A and B | A or B | not A |
|---|---|---|---|---|
True | True | True | True | False |
True | False | False | True | False |
False | True | False | True | True |
False | False | False | False | True |
Module 4 — Packages and Data Structures
Packages in Python
What Is a Module?
A module is a Python file (.py) containing variables, functions, and classes, designed to be imported and reused in other programs.
What Is a Package?
A package is a grouping of related modules sharing a common functionality. It’s the equivalent of a folder in your file system: just as you group your files by category in folders, you organize Python modules in packages.
Using a package:
import camelcase
c = camelcase.CamelCase()
s = 'how are you?'
print(c.hump(s)) # → 'How Are You?'
PyPI — Python Package Index
PyPI (pypi.org) is the official repository of all public Python packages. This is where pip searches for packages during installation.
Using pip
pip is Python’s package manager. It allows installing, updating, and uninstalling third-party packages.
# Install a package
pip install camelcase
pip install jupyter
pip install numpy pandas matplotlib
# Uninstall a package
pip uninstall camelcase
# List installed packages
pip list
# View package details
pip show numpy
# Install a specific version
pip install numpy==1.24.0
# Update a package
pip install --upgrade numpy
# Save dependencies to a file
pip freeze > requirements.txt
# Install dependencies from a file
pip install -r requirements.txt
Importing a package in code:
# Full import
import numpy
# Import with alias (recommended convention)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Selective import (import only what's needed)
from datetime import datetime
from os import path
Data Structures — Overview
A data structure is a way of organizing and storing data efficiently for easier processing.
Python provides three main built-in data structures:
| Data Structure | Symbols | Ordered | Mutable | Duplicates |
|---|---|---|---|---|
| List | [ ] | Yes | Yes (mutable) | Yes |
| Tuple | ( ) | Yes | No (immutable) | Yes |
| Set | { } | No | No* | No |
* A set cannot be modified by indexing, but you can add/remove elements with add() and remove().
Lists
A list is an ordered and mutable collection that can contain elements of different types.
Creating Lists
# String list
my_list = ["Alice", "Bob", "Charlie", "Dave", "Eve"]
print(my_list) # ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve']
print(type(my_list)) # <class 'list'>
# Number list
numbers_list = [1, 2, 3, 4, 5]
# Mixed-type list
mixed_list = [1, 'alice', 2.5]
# Nested list
nested_list = [1, 'alice', 2.5, ['a', 'b', 'c']]
# Empty list
empty_list = []
print(type(empty_list)) # <class 'list'>
Accessing Elements (Indexing)
my_list = ["Alice", "Bob", "Charlie", "Dave", "Eve"]
# Positive indexing (starts at 0)
print(my_list[0]) # Alice
print(my_list[1]) # Bob
# Negative indexing (from the end)
print(my_list[-1]) # Eve
print(my_list[-5]) # Alice (equivalent to index 0)
# Access element in nested list
nested = [1, 'alice', 2.5, ['a', 'b', 'c']]
print(nested[3][1]) # b
Modifying a List
my_list = ["Alice", "Bob", "Charlie", "Dave", "Eve"]
# Modify an existing element
my_list[0] = "Alexandra"
print(my_list) # ['Alexandra', 'Bob', 'Charlie', 'Dave', 'Eve']
# Add an element at the end
my_list.append("Frank")
print(my_list) # ['Alexandra', 'Bob', 'Charlie', 'Dave', 'Eve', 'Frank']
List Characteristics
# 1. MUTABLE
my_list[0] = "Alexandra" # ✓ Works
# 2. ORDERED — element order is preserved
# 3. ALLOWS DUPLICATES
dup_list = ["Alice", "Bob", "Bob", "Charlie"]
print(dup_list) # ["Alice", "Bob", "Bob", "Charlie"] — Bob appears twice
Tuples
A tuple is an ordered and immutable (unmodifiable after creation) collection. Use a tuple when you want to protect data from accidental modification.
Creating Tuples
# String tuple (round parentheses)
my_tuple = ('apple', 'banana', 'cherry')
print(my_tuple) # ('apple', 'banana', 'cherry')
print(type(my_tuple)) # <class 'tuple'>
# Single-element tuple — the trailing comma is mandatory!
single = ('apple') # NOT a tuple — it's a str
print(type(single)) # <class 'str'>
single = ('apple',) # Single-element tuple
print(type(single)) # <class 'tuple'>
# Mixed-type tuple
mixed_tuple = ('apple', 'banana', 'cherry', 10, 11.5)
# Empty tuple
empty_tuple = ()
print(type(empty_tuple)) # <class 'tuple'>
Accessing Elements
my_tuple = ('apple', 'banana', 'cherry')
print(my_tuple[0]) # apple
print(my_tuple[2]) # cherry
# in operator — check element presence
print('apple' in my_tuple) # True
print('apple' not in my_tuple) # False
print('watermelon' in my_tuple) # False
Tuple Packing and Unpacking
# Tuple Packing — group multiple variables into a tuple
name = "Alice"
age = 25
city = "New York"
packed_tuple = name, age, city
print(packed_tuple) # ('Alice', 25, 'New York')
# Tuple Unpacking — decompose a tuple into separate variables
person = ('Alice', 25, 'New York')
name, age, city = person
print(name) # Alice
print(age) # 25
print(city) # New York
# Tuple returned by a function
def get_user_info():
name = "John Doe"
age = 30
city = "Los Angeles"
return name, age, city # implicitly returns a tuple
name, age, city = get_user_info()
print("Name:", name)
print("Age:", age)
print("City:", city)
Tuple Characteristics
my_tuple = ('apple', 'banana', 'cherry')
# 1. IMMUTABLE
my_tuple[0] = "grape" # ✗ TypeError: 'tuple' object does not support item assignment
# 2. ORDERED — order is preserved
# 3. ALLOWS DUPLICATES
dup_tuple = ('apple', 'banana', 'apple') # Valid
Sets
A set is an unordered collection without duplicates. Ideal for storing unique values or performing set operations (union, intersection).
Creating Sets
# String set (curly braces)
my_set = {'alice@example.com', 'bob@example.com', 'charlie@example.com'}
print(my_set) # Order not guaranteed
print(type(my_set)) # <class 'set'>
# Set automatically removes duplicates
dup_set = {'apple', 'banana', 'apple', 'cherry', 'banana'}
print(dup_set) # {'apple', 'banana', 'cherry'} — no duplicates
# Empty set — IMPORTANT: {} creates a dict, not a set
empty_set = set()
print(type(empty_set)) # <class 'set'>
# Create a set from a list
from_list = set([1, 2, 2, 3, 3, 4])
print(from_list) # {1, 2, 3, 4}
Set Operations
set_a = {1, 2, 3, 4, 5}
set_b = {3, 4, 5, 6, 7}
# Union — all elements from both sets
print(set_a | set_b) # {1, 2, 3, 4, 5, 6, 7}
print(set_a.union(set_b))
# Intersection — elements in both sets
print(set_a & set_b) # {3, 4, 5}
print(set_a.intersection(set_b))
# Difference — elements in A but not in B
print(set_a - set_b) # {1, 2}
print(set_a.difference(set_b))
# Check membership
print(3 in set_a) # True
print(6 in set_a) # False
# Add/remove elements
set_a.add(6)
set_a.remove(1) # Raises KeyError if not found
set_a.discard(99) # No error if not found
Reference Diagrams
Python Data Types
graph TD
PY[Python Data Types] --> NUM[Numeric]
PY --> SEQ[Sequence]
PY --> SET_T[Set]
PY --> MAP[Mapping]
PY --> BOOL[Boolean]
PY --> NONE[None]
NUM --> INT[int]
NUM --> FLOAT[float]
NUM --> COMPLEX[complex]
SEQ --> STR[str]
SEQ --> LIST[list]
SEQ --> TUPLE[tuple]
SET_T --> SET_V[set]
SET_T --> FROZENSET[frozenset]
MAP --> DICT[dict]
style INT fill:#4CAF50,color:#fff
style FLOAT fill:#4CAF50,color:#fff
style STR fill:#2196F3,color:#fff
style LIST fill:#FF9800,color:#fff
style TUPLE fill:#9C27B0,color:#fff
style SET_V fill:#F44336,color:#fff
style DICT fill:#00BCD4,color:#fff
Virtual Environment and pip
flowchart LR
PyPI[(PyPI\npypi.org\nPackage Registry)] -->|pip install| LocalEnv[Local Environment\n.venv/]
LocalEnv --> Script[Python Script\napp.py]
Script -->|import| Pkg[Installed\nPackages]
style PyPI fill:#306998,color:#fff
style LocalEnv fill:#FFD43B,color:#000
Reference Tables
Base Types (built-in types)
| Python Type | Keyword | Example | Description |
|---|---|---|---|
| Integer | int | 42, -7 | Whole number |
| Float | float | 3.14, -0.5 | Decimal number |
| Complex | complex | 2+3j | Complex number |
| String | str | "hello", 'world' | Character string |
| Boolean | bool | True, False | True or false value |
| NoneType | None | None | Absence of value |
| List | list | [1, 2, 3] | Ordered mutable collection |
| Tuple | tuple | (1, 2, 3) | Ordered immutable collection |
| Set | set | {1, 2, 3} | Unordered collection without duplicates |
| Dictionary | dict | {'a': 1} | Key-value pairs |
Python Operators
Arithmetic Operators
| Operator | Symbol | Example | Result |
|---|---|---|---|
| Addition | + | 10 + 4 | 14 |
| Subtraction | - | 10 - 4 | 6 |
| Multiplication | * | 10 * 4 | 40 |
| Division | / | 10 / 4 | 2.5 |
| Floor Division | // | 10 // 4 | 2 |
| Modulo | % | 10 % 4 | 2 |
| Exponent | ** | 10 ** 4 | 10000 |
Comparison Operators
| Operator | Symbol | Description |
|---|---|---|
| Equal to | == | Equality |
| Not equal to | != | Inequality |
| Greater than | > | Strictly greater |
| Less than | < | Strictly less |
| Greater or equal | >= | Greater than or equal |
| Less or equal | <= | Less than or equal |
Logical Operators
| Operator | Description | Example |
|---|---|---|
and | True if both operands are True | True and False → False |
or | True if at least one operand is True | True or False → True |
not | Inverts the boolean value | not True → False |
Essential Built-in Functions
| Function | Description | Example |
|---|---|---|
print() | Display a value in the console | print("Hello") |
type() | Return the type of an object | type(42) → <class 'int'> |
len() | Return the length of a sequence | len([1,2,3]) → 3 |
input() | Read user input | name = input("Name: ") |
int() | Convert to integer | int("42") → 42 |
float() | Convert to float | float("3.14") → 3.14 |
str() | Convert to string | str(42) → "42" |
bool() | Convert to boolean | bool(0) → False |
list() | Create or convert to list | list((1,2,3)) → [1,2,3] |
tuple() | Create or convert to tuple | tuple([1,2,3]) → (1,2,3) |
set() | Create or convert to set | set([1,1,2]) → {1,2} |
range() | Generate a number sequence | range(5) → 0,1,2,3,4 |
Data Structures Comparison
| Criterion | List [] | Tuple () | Set {} |
|---|---|---|---|
| Creation | [1, 2, 3] | (1, 2, 3) | {1, 2, 3} |
| Ordered | Yes | Yes | No |
| Mutable | Yes | No | Partially |
| Duplicates | Yes | Yes | No |
| Index access | Yes | Yes | No |
| Use cases | Dynamic collections | Fixed data, function returns | Unique values, set operations |
| Performance | O(n) search | O(n) search | O(1) search |
Search Terms
python · data · essentials · foundations · analysis · engineering · analytics · operators · comparison · packages · science · structures · accessing · arithmetic · built-in · characteristics · elements · identifiers · installing · list · lists · literals · logical · package