Python programming language • Created in 1989 by Guido van Rossum •
Released publicly in 1991 • Named after comic troupe “Monty Python” • Consistently
ranks among the most popular programming languages • High-level, general-
purpose programming language • Known for simplicity, readability, and rich libraries •
Widely used in data science, AI, web development—and finance • Rapidly growing
popularity across industries.Syntax refers to the set of rules that defines the correct
structure and format of statements in a programming language—just like grammar in
English! • Designed for readability • Has similarities with English language,
influenced by mathematics • Uses new line ( ) to complete a command (as opposed
to semicolons or parentheses in other programming languages) • Relies on
indentation, to define scope (scope of loops, functions and classes) as opposed to
curly-brackets in other programming languages. Why Python is Popular in Finance
?? • Handles data analysis, computation, automation, and visualization • Concise,
readable syntax for quick development • Ideal for financial analysts, quants, and
developers • Fewer lines of code than Java or C++. Why Python is Popular in
Finance • Handles data analysis, computation, automation, and visualization •
Concise, readable syntax for quick development • Ideal for financial analysts, quants,
and developers • Fewer lines of code than Java or C++. The Python environment
refers to the setup where Python code is written, executed, and tested. It includes: •
The Python interpreter (which runs Python code) • The command-line or IDE
interface used to write the code • Optional packages and libraries installed for
extended functionality • You can run Python: • In a terminal (using python or python3)
• Through IDEs like PyCharm, VS Code • In notebooks like Jupyter or Colab. The
help() function is a built-in Python function that shows you the documentation
(docstring) of an object, function, module, or class. • It is very handy when you want
to quickly understand what a function does, what parameters it accepts, or see
examples — without leaving your notebook. Code Cell • This is the default cell type.
• Used to write and execute Python code • Outputs (e.g., printed results, plots)
appear directly below the cell. Markdown Cell • Used for formatted text, such as
headings, lists, code blocks, links, and math expressions. • Supports Markdown
syntax and LaTeX for equations. • Does not execute as code. Raw NBConvert Cell •
Contains content that is not evaluated by the notebook interface. • Intended for use
with tools like nbconvert to export the notebook to other formats (e.g., PDF, LaTeX). •
No syntax highlighting or execution occurs here. • Often used for adding custom
export-specific text, instructions, or template. A kernel in Jupyter Notebook is the
computational engine that executes the code contained in the notebook cells. It runs
the backend processes and retains the variable memory throughout your session
until it is restarted or shut down. • Restart kernel: Clears memory (useful when
stuck). • Interrupt kernel: Stops long-running code. • Run all cells: Execute the entire
notebook. • Navigate using Kernel menu or use shortcuts like 0 0 (press 0 twice) to
restart. Comments are lines in code ignored by the Python interpreter. They are
intended for humans reading the code to understand logic, purpose, or assumptions.
A docstring is a multi-line string placed at the beginning of a module, function, class,
or method. It explains what the object does.
Docstrings are used by the help() function and IDEs for generating documentation.
F-strings allow you to insert variable values directly into a string using {}. • Regular
strings will print the curly braces and variable names as-is. In Python, data types
define the kind of value a variable holds • They determine what operations can be
performed on the data. • Basic Built-in Data Types • int: Represents whole numbers
(e.g., x = 10) • float: Represents decimal numbers (e.g., pi = 3.14) • str: Represents
text or character data (e.g., name = “ABC") • bool: Represents boolean values (True
or False). Collection Data Types • list: An ordered, mutable sequence of items (e.g.,
[1, 2, 3]) • tuple: An ordered, immutable sequence (e.g., (1, 2, 3)) • set: An unordered
collection of unique items (e.g., {4, 2, 3}) • dict: Stores key-value pairs (e.g., {"name":
"Alice", "age": 25}) • Type Conversion • Python allows converting between data types
using functions like int(), float(), str(), and list(). • Choosing the right data type
improves memory usage, code readability, and program logic. • Python is
dynamically typed, meaning variable types are determined at runtime—but
understanding them is still key to writing correct and efficient code. In Python, a
variable is a name that refers to a value stored in memory. Variables make it possible
to store, reuse, and manipulate data in your programs. • To create a variable, simply
assign a value using the equals sign (=): name = "Alice" . Rules for naming variables
• Must begin with a letter or underscore (_) • Can contain letters, numbers, and
underscores (A-z, 0-9, and _ ) • Cannot start with a number • Cannot use Python
keywords like if, class, for, etc. • Variable names are case-sensitive (Score and score
are different). Python Operators • Operators are special symbols or keywords in
Python used to perform operations on variables and values.
• Arithmetic Operators + * . Comparison (Relational) Operators == ! . Logical
Operators and or not . Assignment Operators = += -= *.Membership Operators in not
in . Identity Operators is is not.
Conditional statements in Python allow your program to make decisions and execute
code based on whether a condition is true or false. • The if Statement: Executes a
block of code only if a specified condition is true. • The if-else Statement: Adds an
alternative block if the condition is false. • The if-elif-else Chain: Checks multiple
conditions in sequence. • Nesting Conditionals: You can nest if statements inside
others to check multiple levels of conditions. • Boolean Expressions: Conditionals
often use comparison (==, >, etc.) and logical (and, or, not) operators to form
Boolean expressions
Indentation refers to the whitespace at the beginning of a line of code. • In Python,
indentation is not just for readability — it's a crucial part of the language syntax. • It
defines code blocks and ensures code is properly structured. • Why Indentation is
Important • Defines blocks of code such as loops, functions, and conditionals. •
Mandatory in Python – incorrect indentation leads to errors. • Maintains readable and
logical code structure.
General Rules of Indentation • Use consistent indentation: 4 spaces per level is
standard. • Indent blocks of code following a colon (:). • Avoid mixing spaces and
tabs. • Nested blocks require deeper indentation.
What is a Loop? • In programming, a loop is a control structure that allows you to
repeat a block of code multiple times, either a fixed number of times or until a
condition is no longer true. • Each repetition of the code block is called an iteration. •
Loops help avoid repeating the same code manually and are essential for tasks like:
• Repeating actions (e.g., printing numbers from 1 to 100) • Processing items in a list
or string • Waiting for user input or a condition to change. for Loop • Used when you
know how many times to loop • Used when you want to process each item in a
sequence (like a list, tuple, string, or range). • while Loop • Used when you want to
repeat code as long as is True . a certain condition • Use while when the repetition
depends on a condition. • Don’t forget to update your condition in while loops to
prevent infinite loops. Loop Control Statement. Break,continue and pass. The
range() function in Python is commonly used with for loops to generate a sequence
of numbers. • Example: range(5) will generate: 0,1,2,3,4 • range() does not include
the stop value. • A step size can also be specified. • Step can be positive or negative,
but it cannot be zero (it will raise an error). • The range()object is not a list, but it can
be converted using list(range(...)). Slicing in Python: General Syntax sequence[start :
stop : step] • start→ Index to begin from (inclusive) • stop→ Index to stop at
(exclusive) • step→ How many positions to move each time (positive or negative).
Functions in Python • Functions in Python are blocks of reusable code that perform a
specific task. • They help organize code, reduce redundancy, and improve clarity. •
Functions are fundamental building blocks in Python programming and can be built-
in or user-defined. • Defining and Calling Functions • A function is defined using the
`def` keyword followed by the function name and parentheses (). Parameters are
specified within the parentheses if needed. • Functions should be defined before they
are called • Best Practices: Use meaningful function names. Keep functions small
and focused on a single task. Function Syntax in Python def
function_name(parameters): Here, • def: Keyword to define a function •
function_name: Any valid identifier (e.g., greet, calculate_tax) • parameters:
(Optional) Values passed to the function • return: (Optional) Used to send a result
back to the caller. Parameters and Arguments • Parameters are placeholders for
values the function needs to work with. • Arguments are actual values passed when
the function is called. • You can use default, keyword, and variable-length arguments
(using *args and **kwargs). Functions can return a result using the `return` keyword.
Once `return` is executed, the function exits immediately. Types of functions • Built-in
Functions: Predefined by Python (e.g., print(), len(), type(), sum()). • User-defined
Functions: Created by users to perform custom operations. • Advanced: Lambda
Functions: Anonymous, short, single expression functions defined using the `lambda`
keyword. Local Variables in Python Functions • A local variable is defined inside a
function and can only be used within that function. It exists only while the function is
executing. Global Variables in Python Functions • If a variable is declared outside
any function, it is a global variable. Local variables take precedence over global
variables with the same name inside functions.