1.
Python is executed in two steps –
a. Compilation
i. Program is converted into byte code. Byte code can be
run on any OS and software. The file is not explicitly
created. It is handled internally by python.
b. Interpretation
i. The byte code is then converted into machine code. PVM
– Python Virtuall Machine first identifies the OS and
processor, then converts the byte code into machine
code.
ii. Since the PVM takes a lot of time to convert the code
line-by-line, a compiler known as JIT – Just In Time is
added to PVM.
2. Python Terminology
a. Keywords: they are reserved words. Part of the syntax, cannot
be used as identifiers.
b. Variables: names that reference a memory location where
data is stored. They are user defined.
c. Functions: sequence of instructions that perform a specific
task.
d. Classes: blueprints for creating objects. They encapsulate data
for objects and methods to manipulate the data.
e. Objects: they are instances of the classes.
f. Modules: help in reusing the code.
i. import math
ii. print([Link](5))
F-Strings (Formatted Strings)
You asked for a refresher on this. F-strings are the modern, clean way to inject variables
directly into text.
The Rule:
1. Put a little f right before the opening quote.
2. Put your variable inside curly braces {}.
Without f-string (The old, hard way):
Python
epoch = 5
loss = 0.2
# Hard to read!
print("Epoch number " + str(epoch) + " has a loss of " + str(loss))
With f-string (The easy way):
Python
epoch = 5
loss = 0.2
# Clean and readable
print(f"Epoch number {epoch} has a loss of {loss}")
Pro Tip for ML: You can even do math inside the braces!
Python
correct = 8
total = 10
print(f"Accuracy: {correct / total}")
# Output: Accuracy: 0.8
What is Pandas?
Think of Pandas as "Excel for Python".
In "Pure Python", we stored data in Lists: [1, 2, 3].
In Pandas, we store data in a DataFrame. It looks exactly like a spreadsheet with
rows and columns, but it's much faster and programmable.
In Python, a dictionary is a collection of Key: Value pairs.
The Keys (strings like "Accuracy") become the Column Headers.
The Values (lists like [0.85, 0.92]) become the Column Data.
When we run [Link](data), Pandas takes those vertical lists and stitches them
together side-by-side to make a table.
NUMPY