Python
For Data Engineering & Analytics
What is Python?
High-level language
Dynamically typed
Interpreted
programming language. Known for its simplicity and readability.
Its case sensitive language
PIP is the package manager
Attention to indentation is required
Compiled & Interpreted languages
In Compiling the entire source code is translated into machine
code by a compiler before execution. This machine code is directly
executed by the CPU at runtime causing faster processing.Many
errors can be caught at compile time, before the program runs.
Eg: C , C# , Java
Code Complied Low level conversion Execution Output
In Interpreted language the source code is read and executed line-
by-line by an interpreter at runtime. Generally slower because
each instruction is interpreted on the fly.Errors are caught at
runtime, which can make debugging more difficult but allows for
more flexibility.
Eg: Python , JS
Code Interpreted conversion & execution Output
at run time
Python’s hybrid nature
It is both compiled and interpreted. When you run a Python
program, the source code is first compiled into bytecode, which is
an intermediate representation of the code. The bytecode is then
executed by the Python Virtual Machine, which converts it into
machine code and executes it on the computer.
.py Code Bytecode conversion Bytecode converted by
Execution Output
using Cython compiler PVM to Machine code
Source Code (.py files): You write your Python code in .py files
using a text editor or an IDE.
Bytecode Compilation:
When we run a Python script (Calculator.py), the Python
interpreter (e.g., CPython) first compiles the source code into
bytecode.
“Bytecode is a low-level, platform-independent representation of
your Python code. It's stored in .pyc files (compiled Python files),
typically in a __pycache__ directory.”
Python Virtual Machine (PVM):
The bytecode generated by the compiler is executed by the Python
Virtual Machine (PVM).
The PVM is part of the Python interpreter and is responsible for
translating bytecode instructions into machine code instructions
that the CPU can execute.
Execution:
The PVM executes the bytecode instructions sequentially,
performing the operations defined in your Python code.
This results in the desired output or behaviour based on the logic
and algorithms you've written in our .py file.
Print Function
The print() function in Python is used to output text or other data
to the console or standard output device.
“Usually you can relate with like you give your calculator 10+20
and you gets 30 as an output , so the display of output given by
calculator is done by print statement ”
Sep parameter :
It's used to add a separator between the statements , taken as an
argument in print function.
End parameter :
It's used to print new statement in the same line without going to
the next line , taken as an argument in print function.
By default, the print function ends with a newline character (\n),
which moves the cursor to the next line. By changing the value of
the end parameter
Variables
The variables are the object in python that is used to store a literal
value
In Python, you don’t need to declare a variable before using it.
You can directly assign a value to a variable.
Variables can store different types of data, such as integers,
floats, strings, lists, tuples, dictionaries, and more.
Variables usually point a memory location where a memory is
occupied by a data type
If i say Var = 100 Var is a variable here that is locating a particular
memory slot where the data (100) is been stored
Memory address
What if we assign diffrent variable with same value ??
Var1
What if we assign diffrent value to the same variable ??