2026-08-25 17:05

Status:


PDSAD - Module 1 - Python Basics

==Getting Started with Python and Jupyter

  • Introduction to Python:
    • Python is a very popular and well used programming language used inside of the world of data science, it has a bunch of different support for things like Machine Learning, Data Science, and Scripting

    • Who is Python For?

    • If you already know how to program then you can use python’s easy and light syntax to help you make programs faster (even if they run slower)

    • You can also use python for scripting and accomplishing basic tasks with having it interact with a given environment

    • You can then also have it be good for people who are new to programming and want to learn a language

    • Over 80% of data professionals use python worldwide

    • Large organizations like IBM, Google, Wikipedia, NASA, Amazon, and so many more use python

    • Python is high level and general purpose, with a large standard library that is very good for a ton of things like machine learning, image processing, and any other really good stuff with processing or doing stuff to data

    • It is general purpose and can be used for building applications as well, with a lot of different frameworks and what not

    • Common libraries for data science in python include Pandas, Numpy, SciPy, and Matplotlib

    • Common libraries for AI and Machine Learning Include- `TensorFlow, PyTorch, and Scikit-learn

    • Common natural language (like English I guess) processing include Natural Language Toolkit NLTK

    • The python community is also very diverse and inclusion and is basically really good from a political and social moral standing as well, at least I think so

  • Introduction to Jupyter:
    • Jupyter is a freely available web application that enables creation and sharing of documents containing equations, live coding, visualizations, and narrative text. Jupyter provides an interactive computing environment that supports multiple programming languages, including Python, R, Julia, and more, but it shines brightest when used with Python.
    • Jupyter revolves around notebooks, documents containing a mix of code, visualizations, narrative text, equations, and multimedia content. These notebooks allow users to create, share, and collaborate on computational projects seamlessly
    • Jupyter- enables users to write and execute code interactively, meaning they can run code cells individually and see the output immediately
    • It allows for generation of interactive plots what include things like charts, images, and videos
    • This makes visualization of data, communicating data findings, and more a lot easier
    • It integrates very well with things like NumPy, Pandas, Matplotlib, sci-kit learn, TensorFlow, & PyTorch, making jupyter very good for integration with data science
  • Getting Started with Jupyter:
    • Pasted image 20260825173649.png

    • So basically it seems that a given notebook inside of juypter, outside of whatever the fuck this course wants you to do, is basically create some sort of special ipynb (IPython Notebook) file or something like that

    • You can then rename a given notebook and run the code inside of your notebook

    • Pasted image 20260825173916.png

    • Each notebook seems to have something called a cell which it can have multiple of, and you can add or delete them as you wish

    • It seems that these notebooks and cells might also exist inside of some given program or something like that, although I do believe they can exist on the web browser too

    • Pasted image 20260825173933.png

    • You can also have more than a single note book at a time, and basically it seems like this creates a new file that you can add cells to and then run this code inside of different environments

    • Jupyter also I believe would then let you actually use things like markdown inside of it as well as a means to convey what is really happening with your given data presentation

    • This feels more like something similar to obsidian where you have just a tool for annotation and presentation that can also just do things like run code inside of it

    • This is the thing that actually matters and that most intro material glosses over. When you open a notebook, it starts a kernel — a running background process (usually Python) that actually executes your code and holds onto variables in memory between cells. That’s why you can define a variable in cell 1 and use it in cell 5 — the kernel remembers. It also means you can run cells out of order, which is a common source of bugs when a notebook’s displayed order doesn’t match the execution order. If you ever see weird “undefined variable” errors, it’s usually a kernel state issue, not a code issue.

    • Jupyter also allows you to basically create slides of the data and math that you want to present making it very simple to create and output something that is understandable

      • Jupyter is a tool for writing documents that mix three things in one file: code you can run, the output of that code, and formatted text/notes explaining it. Think of it as a notebook where instead of just writing “here’s my analysis,” you actually embed the code that produced the analysis, and the results appear right there, inline, next to your explanation.

==Types

  • Types:
    • A Type is how python represents different types of data inside of memory in the program that you are running

    • I literally wrote my own language with it’s own different types and what not, and under the hood what they all really are is just a different number of bytes for different levels of specification

    • There is generally things like ints, floats, doubles, shorts, booleans and what not, which are the basic numeric types, each having different bytes of memory assigned over to them with 4, 4, 8, 2, 1, for the ones mentioned above, they would all be held in some union in a C struct somewhere inside of the python environment

    • As for more complicated data structures, those being either null or none I think is the right one in python, and then also strings which have arbitrary length, those are basically just a pointer to an array in memory that stores chars, which are 1 byte each in size

    • Obviously this is all handled a little differently and what not based on the language, and python also had changing types based on a given context, letting you override types and what not but still

    • There is also the whole chunk array and then the value array inside of a chunk array, and then objects and functions and all that good jazz, if you want to know more check out Syntax for Oli-Nat programming language and the eventual documentation for it I plan to write up for more detail

==Expressions and Variables

  • Expressions and Variables:
    • ONCE AGAIN I’VE WRITTEN MY OWN PROGRAMMING LANGUAGE
    • Okay so basically an expression is some line of code that is not either condition or is not an assignment to something like a variable, although that last one is a bit more iffy of a statement
    • Generally they are things like actually modifying the data that would exist in your program, something like 32+2-9/43; is an expression, it should generally take up only one line of code as well, but of course its not a concrete standard
    • Expressions are also generally a part of the other two things I mentioned like assignment and conditions, where something like the if(True == 1) is basically a condition with the True == 1 being the expression, yes booleans are also expressions

==String Operations

  • String Operations:
    • As previously said, a string is basically just a pointer to an array in memory containing a bunch of different chars that would basically spell out a word
    • Inside of my own programming language, and probably python too, they are actually their own object structures that hold their own memory and metadata separate from the actual source string but thats for another time
    • In python you can declare strings like you can with literally every other language like "This is a string" or 'This should be a char but is a string because fuck you'
    • You can also have spaces in them, special characters, have them be added and spliced and do all of the good string operations on them that you want
    • You can also treat them as an array “Because they are one”, and so you can basically index them and use things like the python string[::2] to get every second character of a string and whatever you would want
    • You can use the len() function in order to find the length of a string, and then basically it’s just strings man, you know what these are

==Summary / Glossary

  • Python can distinguish among data types such as integers, floats, strings, and Booleans.
  • Integers are whole numbers that can be positive or negative.
  • Floats are numbers that have decimal points; they can represent whole or fractional values.
  • You can convert integers to floats using typecasting and vice-versa.
  • You can convert integers and floats to strings.
  • You can convert an integer or float to a Boolean: 0 becomes False, non-zero becomes True.
  • Expressions in Python are a combination of values and operations used to produce a single result.
  • Expressions perform mathematical operations such as addition, subtraction, multiplication, and so on.
  • We can use // to perform integer division, which results in an integer value by discarding the fractional part.
  • Python follows the order of operations (BODMAS) to perform operations with multiple expressions.
  • Variables store and manipulate data, allowing you to access and modify values throughout your code.
  • The assignment operator ”=” assigns a value to a variable.
  • Assigning another value to the same variable overrides the previous value of that variable.
  • You can perform mathematical operations on variables using the same or different variables.
  • Modifying the value of one variable will affect other variables only if they reference the same mutable object.
  • Python string operations involve manipulating text data using tasks such as indexing, concatenation, slicing, and formatting.
  • A string is usually written within double quotes or single quotes, including letters, white space, digits, or special characters.
  • A string can be assigned to a variable and is an ordered sequence of characters.
  • Characters in a string identify their index numbers, which can be positive or negative.
  • Strings are sequences that support operations like indexing and slicing.
  • You can input a stride value to perform slicing while operating on a string.
  • Operations like concatenation and replication produce new strings, while finding the length of a string returns a number.
  • You cannot modify an existing string; they are immutable. 
  • You can use escape sequences with a backslash () to change the layout of a string. (For example, \n for a new line, \t for a tab, and \ for a backslash, etc.)
  • In Python, you perform tasks such as searching, modifying, and formatting text data with its pre-built string methods.
  • You apply a method to a string to change its value, resulting in another string. 
  • You can perform actions such as changing the case of characters in a string, replacing items in a string, finding items in a string, and so on using pre-built string methods.

==Cheat Sheet

Package/MethodDescriptionCode Example
CommentsComments are lines of text that are ignored by the Python interpreter when executing the code<./td># This is a comment
ConcatenationCombines (concatenates) strings.Syntax:

5concatenated_string = string1 + string2

Example:

result = “Hello” + ” John”
Data Types- Integer - Float - Boolean - StringExample:

x=7

# Integer Value

y=12.4

# Float Value

is_valid = True

# Boolean Value

is_valid = False

# Boolean Value

F_Name = “John”

# String Value
IndexingAccesses character at a specific index.Example:

my_string=“Hello”

char = my_string[0]
len()Returns the length of a string.Syntax:

len(string_name)

Example:

my_string=“Hello”

length = len(my_string)
lower()Converts string to lowercase.Example:

my_string=“Hello”

uppercase_text = my_string.lower()
print()Prints the message or variable inside ().Example:

print(“Hello, world”) print(a+b)
Python Operators- Addition (+): Adds two values together.- Subtraction (-): Subtracts one value from another.- Multiplication (*): Multiplies two values.- Division (/): Divides one value by another, returns a float.- Floor Division (//): Divides one value by another, returns the quotient as an integer.- Modulo (%): Returns the remainder after division.Example:

x = 9 y = 4

result_add= x + y # Addition

result_sub= x - y # Subtraction

result_mul= x * y # Multiplication

result_div= x / y # Division

result_fdiv= x // y # Floor Division

result_mod= x % y # Modulo
replace()Replaces substrings.Example:

my_string=“Hello”

new_text = my_string.replace(“Hello”, “Hi”)
SlicingExtracts a portion of the string.Syntax:

substring = string_name[start:end]

Example:

my_string=“Hello” substring = my_string[0:5]
split()Splits string into a list based on a delimiter.Example:

my_string=“Hello”

split_text = my_string.split(”,“)
strip()Removes leading/trailing whitespace.Example:

my_string=“Hello”

trimmed = my_string.strip()
upper()Converts string to uppercase.Example:

my_string=“Hello”

uppercase_text = my_string.upper()
Variable AssignmentAssigns a value to a variable.Syntax:

variable_name = value

Example:

name=“John” # assigning John to variable name

x = 5 # assigning 5 to variable x

References