Topic | Definition | Purpose | Example |
---|---|---|---|
Python Intro | A high-level, readable programming language. | To write programs for automation, web dev, data analysis, etc. |
|
Variables | Containers for storing data values. | To store and reuse values throughout a program. |
|
Types | Classifications of data (int, float, str, etc.). | To define what kind of data is being used. |
|
Branching | Allows decision-making using conditions. | To execute different code paths based on logic. |
|
While Loop | Repeats a block of code as long as a condition is true. | Useful when the number of iterations isn't known. |
|
For Loop | Iterates over a sequence (like a list or range). | To repeat tasks a known number of times or over collections. |
|
Functions | Reusable blocks of code with a name. | To organize code and perform tasks multiple times. |
|
Strings | Text data enclosed in quotes. | To store and manipulate text. |
|
Lists / Dicts | List: ordered collection; Dict: key-value pairs. | To store multiple items in a single variable. |
|
Classes | Blueprint for creating objects (OOP). | To model real-world entities and use object-oriented principles. |
|
Exceptions | Errors caught and handled during execution. | To make code more robust by handling errors gracefully. |
|
Modules | Files containing Python code (functions, classes, etc.). | To organize and reuse code across files. |
|
Files | Input/output operations on text/binary files. | To read from or write to external files. |
|
Plotting | Visual representation of data (often using libraries). | To analyze and visualize data. |
|
I.Introduction to Python
Python is a programming language that is used for algorithms and machine learning.
Python is both compiled and interpreted.
Syntax error: when the program contains invalid code that can't be understood
Identifiers are variable names. Reserved words, however, cannot be used because they already have a specific purpose.
Arithmetic operators: Normal division keeps the remainder (/), while Floor division removes the remainder (//)
II.Variables / data types
Python core data types: Lists, integers, strings, dictionaries, tuples, boolean, sets.
Len counts the number of elements or characters in a list or string
When indexing using negatives, you do not start from 0 as you would with regular indexing. Instead, you start with 1 and countdown.
The insert method (used in lists) assigns an index to a value. So (2,67) would replace index 2 with the value 67.
If you multiply a list by an integer, the list will duplicate itself, not actually multiply the values by the integer.
Tuples cannot be updated or changed. They store finalized data.
The insert method can only be used with a list. So if you wanted to update a tuple, for example, you would have to convert the tuple to a list.
Ex: my_list = list(tuple_name)
my_list.insert(3,20)
To delete a value from a dictionary, use del to accomplish it. Ex: def d1[“John”] Remember, use brackets instead of parenthesis.
Retrieval: d1.get(“Susan”) → gives us the value or age (42)
To check if a list contains a certain value, use the following syntax: 15 in my_list
III. If statements
If statements do not require else statements, however, else statements must have an accompanying if statement in order to be appropriately used.
Blocks are represented by indentation.
= is used to assign a data type to a variable, while == is used to write statements within if, for, or while loops.
If your if statement is correct, It will execute the code below it, if not, however, it will move on to else statements.