Python L1
Python L1
CS 1214
Wanzita Shilla
Assistant. Lecturer
ISNE
The Outline
1. Introduction to Python
2. What is algorithms?
3. What is pseudo code?
TREY
2
research
Introduction to Python
Definition:
Python is a high-level, interpreted programming language known for its simplicity, readability, and
versatility.
Features of Python:
Readability: designed to be easily readable and understandable. It uses indentation to define code blocks,
making it visually clean and intuitive.
Versatility: Multipurpose language used in various domains such as web development, data science,
artificial intelligence, automation, scientific computing, and more. Its extensive standard library and third-
party packages make it suitable for diverse applications.
Interpreted: Executed line by line by the Python interpreter, which converts the code into machine-
readable bytecode. This makes development and debugging easier as code can be tested immediately
without compilation.
TREY
3
research
Introduction to Python
Features of Python:
Dynamic Typing: dynamically typed, meaning you don't need to explicitly declare variable types. Variables
can change type during runtime, offering flexibility but requiring careful attention to data types in certain
situations.
Object-Oriented: Object-oriented programming (OOP) principles such as classes, inheritance, encapsulation,
and polymorphism. This makes it suitable for developing large-scale, modular, and reusable codebases.
Extensive Standard Library: comes with a vast standard library that provides modules and functions for
various tasks like file handling, networking, data processing, and more. This reduces the need for external
dependencies for many common functionalities.
Community and Ecosystem: has a large and active community of developers contributing to its ecosystem.
The availability of third-party libraries and frameworks like NumPy, Pandas, Django, Flask, TensorFlow, and
PyTorch further enhances Python's capabilities for specific domains.
TREY
4
research
What is algorithms?
Algorithms are step-by-step procedures or formulas used for problem-solving and
computation.
In Python programming, algorithms are implemented using functions and control flow
structures like loops and conditional statements.
TREY
5
research
SELECTION SORT ALGORITHM
def selection_sort(arr):
n = len(arr)
for i in range(n):
min_idx = i for j in range(i+1, n):
if arr[j] < arr[min_idx]:
min_idx = j arr[i], arr[min_idx] = arr[min_idx], arr[i]
return arr
TREY
6
research
INSERTION SORT:
Builds a sorted list one element at a time by repeatedly taking the next element and inserting it into its
correct position among the already sorted elements.
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j=i-1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
return arr
TREY
7
research
SEQUENTIAL SEARCH:
Linear search through a list from start to end to find a target element.
TREY
10
research
Thank You Wanzita Shilla
+255716578677
elwanzita20s@gmail.com
TREY
11
research