Python

Python Fundamentals

Learn Python data types, data structures, conditions, loops, functions, classes, data analysis, web development, GUI development, and deep learning.

Thursday 3 September

7 blocks
0 of 6

All About Python

1 of 6

Topic 1 - Data Types

name = "ibrahim"   # string
age = 20           # integer
height = 5.8       # float
student = True     # boolean
2 of 6

Topic 2 - Data Structures

fruits = ["apple", "orange", "mango"]           # list
fruits = ("apple", "orange", "mango")           # tuple
fruits = {"apple", "orange", "mango"}           # set
fruits = {0: "apple", 2: "orange", 5: "mango"}  # dictionary

Comparison of Data Structures

Feature List Tuple Set Dictionary
Mutable Yes No Yes Yes
Allows duplicates Yes Yes No No duplicate keys
Indexed access Yes Yes No By key
Add item append() Not possible add() dict[key] = value
Remove item remove() Not possible remove() del dict[key]
3 of 6

Topic 3 - Conditions

temp = 29

if temp > 30:
    print("turn on fan")
else:
    print("turn off fan")

Comparison Operators

Type Example Meaning
Equal 5 == 5 True if same
Not equal 5 != 3 True if different
Greater than 10 > 2 True if left is bigger
Less than 2 < 10 True if left is smaller
Greater or equal 5 >= 5 True if bigger or same
Less or equal 4 <= 6 True if smaller or same

Logical Operators

age > 18 and age < 60
city == "Paris" or city == "London"
not is_raining

if-elif-else

if score > 90:
    print("A")
elif score > 80:
    print("B")
else:
    print("C")

Nested if

if age > 18:
    if age < 25:
        print("Young Adult")
4 of 6

Topic 4 - Loops

For Loop

for i in range(10):
    print(i)  # prints from 0 to 9

While Loop

i = 0

while i < 10:
    print(i)  # prints from 0 to 9
    i += 1
5 of 6

Topic 5 - Functions

def add(a, b):
    print(a + b)

add(10, 20)
add(2, 5)

Function Arguments

Argument Type Definition Example
Positional def func(a, b) func(10, 20)
Keyword def func(a, b) func(a=10, b=20)
Default def func(a=5, b=10) func()
Extra positional def func(*args) func(1, 2, 3, 4)
Extra keyword def func(**kwargs) func(name="Ali", age=28)
Positional-only def func(a, b, /) func(10, 20)
Keyword-only def func(*, x, y) func(x=5, y=10)
Lambda lambda x, y: x + y add(3, 5)
Multiple return return a, b x, y = func(3, 5)
Docstring """Explain here""" help(func)
Empty function pass def func(): pass
6 of 6

Topic 6 - Classes

class Cat:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def what_is_name(self):
        print("name is", self.name)

Data Analysis

  1. NumPy — numerical Python library for mathematical operations on arrays.
  2. Pandas — used to load and manipulate data.
  3. Matplotlib — used for plotting graphs.

Website Making

  1. Flask — a lightweight web application framework.
  2. Django — a comprehensive framework for complex websites.
  3. Streamlit — a fast framework for data-related web applications.

Desktop Applications or GUIs

  1. Tkinter
  2. Turtle
  3. Pygame
  4. PyQt5

Deep Learning

  1. PyTorch
  2. TensorFlow