This repository contains a collection of Python scripts designed to teach core programming concepts. The files range from basic syntax to Object-Oriented Programming (OOP) and file handling.
hello.py- Core Concepts: Basic printing, single and multi-line comments, and variable assignment.
- Data Types: Covers Strings (
str), Integers (int), Floats (float), and Booleans (bool). - Modules: Demonstrates importing standard libraries like
math(forpiandsqrt) andrandom.
loops_and_conditions.py- Conditionals: Usage of
if,elif, andelsestatements for decision making. - Loops:
forloops iterating over lists and ranges.whileloops with counters.
- Flow Control: Implementation of
continueto skip iterations andelseblocks within loops.
- Conditionals: Usage of
lists.py- Lists: Creating lists and using methods like
.append(),.insert(),.remove(),.pop(),.reverse(), and.sort(). - Dictionaries: Creating key-value pairs, accessing data safely with
.get(), updating values, and removing keys. - Tuples: Immutable sequences and indexing.
- Sets: Handling unique collections and adding items.
- Lists: Creating lists and using methods like
functions.py- Definitions: Creating functions using
def, handling parameters, and returning values. - Arguments: Using default argument values (e.g.,
width=10). - Lambdas: Introduction to anonymous functions (e.g.,
lambda x: x ** x).
- Definitions: Creating functions using
classes.py- Classes & Objects: Defining classes (e.g.,
Cat), constructors (__init__), and methods. - Encapsulation: Using protected attributes (like
_balance) and getter/setter patterns in anAccountclass. - Inheritance: Creating child classes (e.g.,
Mammalinheriting fromAnimal) and usingsuper(). - Polymorphism: Demonstrating method overriding and abstract concepts with
Shape,Circle, andSquare.
- Classes & Objects: Defining classes (e.g.,
io.py- File I/O: Reading (
r), writing (w), and appending (a) to text files. - Context Managers: Using the
withstatement to automatically close files. - Error Handling: Implementing
tryandexceptblocks to catch errors likeFileNotFoundError.
- File I/O: Reading (
Ensure you have Python installed. You can run any of the scripts using your terminal or command prompt:
# Example: Run the basics script
python hello.py
# Example: Run the OOP examples
python classes.py