Resources
PythonSemester 2All

Python for Engineers

Syntax, data structures, OOP in Python, libraries for engineering.

12 min read3 sectionsExam-ready notes

Key points

  • Lists, tuples, dicts, sets
  • Functions & comprehensions
  • OOP in Python
  • File I/O & exceptions
  • NumPy / Matplotlib intro

1. Core Syntax

Indentation defines blocks. Dynamic typing.

x = 10          # int
name = "BH"     # str
nums = [1,2,3]  # list

Control: if/elif/else, for, while, break/continue

Functions: def, *args, **kwargs, lambda

2. Data Structures

  • list — mutable, ordered
  • tuple — immutable
  • dict — key→value, O(1) avg
  • set — unique, unordered

Comprehensions

[x*x for x in range(10) if x%2==0]

Slicing: a[start:stop:step]

3. OOP & Libraries

class Student:
    def __init__(self, name):
        self.name = name

Libraries

  • NumPy — arrays & math
  • Pandas — dataframes
  • Matplotlib — plotting
  • requests — HTTP

File I/O: with open("f.txt") as f: ...

Exceptions: try/except/finally