🐍

Beginner's Guide to Python Programming

May 28, 2025

Lecture Notes: Coding with Python Lecture

Introduction

  • Overview of the course: Introduction to Python programming
  • 20 hands-on projects included
  • Final project: Weather app fetching real-time data from an API
  • Basic setup: Python interpreter and IDE (PyCharm recommended for beginners)

Python Setup

  • Download Python interpreter from python.org
  • Add Python to system path
  • Install an IDE like PyCharm (Community Edition recommended) or VS Code
  • PyCharm: JetBrains website, select Community Edition

First Python Program

  • Create a new Python project and file (e.g., main.py)
  • Print statements: print("I like pizza")
  • Comments with #: Used for notes within the code

Basics: Variables

  • Variables: Containers for values
  • Data types: Strings, Integers, Floats, Booleans
  • Assign and print variables
  • Concatenate strings using f-strings

Type Casting

  • Convert data types: int(), float(), str(), bool()
  • Example: Convert GPA from float to integer

User Input

  • Use input() function to accept user data
  • Type casting inputs for calculations, e.g., converting input to int
  • Exercise: Calculate area of a rectangle

String Manipulation

  • Use of various string methods like capitalize(), upper(), lower()
  • Manipulate and validate strings

Math Functions

  • Basic arithmetic and built-in functions from the math module
  • Using import math for mathematical constants and functions
  • Exercises: Calculate circumference and area of a circle

Conditional Statements

  • if, else, and elif for decision making
  • Boolean expressions for conditions

Loops

  • while and for loops for iteration
  • Use break and continue to control loop execution
  • Practical example: Countdown timer

Functions

  • Definition and invocation of functions
  • Function parameters and return values
  • Example project: Basic calculator using functions

Object-Oriented Programming (OOP)

  • Classes and objects: Basic concepts and definitions
  • Attributes and methods
  • Inheritance and polymorphism
  • Example: Car class with attributes and methods

File Handling

  • Reading and writing to files in different formats (txt, JSON, CSV)
  • Example: Writing a shopping cart program

Error Handling

  • Use of try, except, and finally for exception handling

Graphical User Interface (GUI) with PyQT5

  • Setting up a basic GUI application
  • Widgets like QLabel, QPushButton, QLineEdit
  • Layouts: QVBoxLayout, QHBoxLayout, QGridLayout

API Integration

  • Making requests with the requests library
  • Example project: Weather app integrating with an API

Conclusion

  • Completion of the weather app as a final project
  • Encouragement to continue exploring and building projects in Python