SlideShare a Scribd company logo
Introduction to Python
1
By: Asmaa Mahmoud Saeed
Asmaa Mahmoud Saeed
ITI
•
•
MSc, Computer Science
•AAST
Bachelor of Science , Menoufia University
• Computer Science
2
https://www.linkedin.com/in/asmaa-m-491750194/
Work.asmaa@gmail.com
Contact me
Sessions Content
Introduction to Python
Working with
files
Data types, Working
with Data Structure
5
S1
S2
S3
S4
s5
Conditional statement-
Looping and iteration
S5 Python Modules and
Libraries
Introduction
The session is designed to learn
how to use one of the best
programming language for
different applications, like:
3
Python
Machine
learning
web
Application
Data
Science
network
servers
-Rank of Python (5) in 2020
Python
Tools and Environment setup
1. Google colab
https://colab.research.google.com/
Tools and Environment setup
1. Anaconda
https://www.anaconda.com/download
Recommended(Python 3.12)
Tools and Environment setup
Tools and Environment setup
Tools and Environment setup
Tools and Environment setup
Jupyter Notebook
Jupyter Lab
Basic I/P and O/P Operation :
O/P Function :
•Print to the screen what you write !
Hello world
Basic I/P and O/P Operation :
I/P Function :
•It always reads the input as a string •Two ways to use it:
•input() which reads directly •input(msg) which prints a message first
Topics Hands-on (I)
•Syntax,Reserved words,Line Identiation ,comment.
•Conditions and Loops
•Lists, Tuples , Dictionaries
•OOP and Classes Component
•Arithmetics, Assignment, Comparison, Logic Gates
Python Syntax Rules
Variables & Data Types
Operators
Data Structures
Control Flow
Functions
Classes
List Comprehension & Lambda
File Handling in Python
Python is loosely typed language
Syntax:
Python Identifier:a name used to identify a
Case Sensitive
Variable function,class, module or other object
Python is Language
Reserved Words :
-A Python identifier doesn’t be one of Reserved words
Line Indentations :
Quotes … 1.. 2 ... 3 :
Comments :
Variables :
-Declare a Variable
Data Types :
NaN (Not a Number): NaN represents missing or undefined data in Python.
Data Types :
-Type conversion
Operators :
-Arithmetic
Operators :
-Assignment
Operators :
-Comparison
Boolean Operators :
-Logic Gates
Boolean Operators :
-Logic Gates
Strings:
Strings:
-Methods
Strings:
-String Formatting
Numbers :
-Types
32-bit(2 billion)
64-bit(9 quintillion)
Numbers :
-Conversion Numbers
Numbers :
-Methods
R = max(x,y)
Data Structures:
-Lists : Container for heterogeneous Data Type
=list()
Data Structures:
-Lists:
-Method
0
1
2
3
4 php
Data Structures:
-Lists:
-Method
Data Structures:
-Lists:
-Method
Data Structures:
-Lists:
-Method
Data Structures:
-Lists:
-Method
Data Structures:
Sets:
Set items are unordered, unchangeable, and do not allow duplicate values.
Unordered
Unordered means that the items in a set do not have a defined order.
Set items can appear in a different order every time you use them, and cannot be referred
to by index or key
Unchangeable
Set items are unchangeable, meaning that we cannot change the items after the set has
been created.
Duplicates Not Allowed
Sets cannot have two items with the same value.
Data Structures:
-Tuples:Immutable Lists
Data Structures:
-Dictionaries:key/value Pairs
Data Structures:
-Dictionaries:Methods
Control Flow:
- Conditions: IF Statement
Control Flow:
- Loops: for..in
s
s
Control Flow:
- Loops: Range Function
Control Flow:
- Loops: While
Control Flow:
- Loops: Break Statement
Control Flow:
- Loops: Continue Statement
Control Flow:
- Loops: Else Statement
Control Flow:
- Loops: Pass Statement
Functions:
Functions:Defining
Functions:Default Argument
Functions: *arguments (unknown No Of argument)
Functions: **keywords (unknown No Of Keywords)
Object oriented programming
(OOP)
Why OOP?:
Motivation:
•Imagine we are creating a system for a company
•It has many departments Each department has employees
•Each employee has information: name, age, address, salary, etc
•And much more information and relationships
Motivation:
(OOP KeyWords):
Class:
•Example
class Company:
pass
•A class is a template definition of an object's properties and
methods.
(OOP KeyWords):
Object:
•
Example
comp=Company()
An Object is an instance on a Class.
(OOP KeyWords):
Constructor:
Constructor is a method called at the moment an object is instantiated.
Example
:
:
(OOP KeyWords):
Instance variables: is an object characteristic, such as name.
(OOP KeyWords):
Class variables: is the variable that shared by all instances.
(OOP KeyWords):
Instance Method:
is an object capability, such
as walk.
(OOP KeyWords):
Class Method:
is a method that shared by all
instances of the Class
(OOP KeyWords):
:
Static Method
is a normal function that have
logic that related to the Class
LET’S PRACTICE
SOME EXAMPLES
Practical Examples (I)
Let’s open the following notebook:
Notebook Name: python basics.ipynb
70
List Comprehension & Lambda Fn :
Lambda Function:
File Handling :
- Opening File : Text(.txt,.c,.cpp) ,Json file, CSV
File Handling :
Mix reading and writing:
File Handling :
-Closing File :
File Handling :
Reading : open, read and close
File Handling :
Reading: Reading Line :read all the file content!
File Handling :
Reading: .read().splitlines
File Handling :
Writing: The write method doesn’t add new line. If you want it, you have to provide it
By default, the old content will be overwritten
File Handling :
Writing:
PrintLines: Just add n to force print new line
File Handling :
Writing:
Appending mode: ●The append mode just keep adding things to the end of the file
• Each run will add new content, not overwriting
LET’S PRACTICE
SOME EXAMPLES
Modules
Module:
A module is a file that contains code to perform a specific task. A module may contain
variables, functions, classes etc
Module types :
1-Built-in Module :
Python built-in modules are a set of libraries that come pre-installed with the
Python installation
Examples: math,time,random,…etc.
2-External modules:
External modules are collections of pre-written code that offer additional
functions, classes, or methods not available in Python's standard library.
Examples: Numpy,pandas,Matplotlib…etc.
Python math Module
1.Python has a built-in module that you can use for mathematical
tasks.
2. The math module has a set of methods and constant.
3. The math module gives us access to hyperbolic , trignometric ,
and logarithmic functions for real numbers and cmath module
allows us to work with mathematical functions
Arithmetic Functions
These functions perform various arithmetic operations like calculating the floor,
ceiling, or absolute value of a number using the floor(x), ceil(x), and fabs(x)
functions respectively.
The function ceil(x) will return the smallest integer that is greater than or
equal to x.
Similarly, floor(x) returns the largest integer less than or equal to x.
The fabs(x) function returns the absolute value of x.
You can also perform non-trivial operations like calculating the factorial of
a number using factorial(x)
Arithmetic Functions
Trigonometric Functions
You can calculate sin(x), cos(x), and tan(x) directly
using this module.
However, there is no direct formula to calculate
cosec(x), sec(x), and cot(x), but their value is
equal to the reciprocal of the value returned by
sin(x), cos(x), and tan(x) respectively
Trigonometric Functions
Hyperbolic functions
Hyperbolic functions are analogs of trigonometric functions that are based on a
hyperbola instead of a circle.
In trigonometry, the points (cos b, sin b) represent the points of a unit circle. In
the case of hyperbolic functions, the points (cosh b, sinh b) represent the
points that form the right half of an equilateral hyperbola.
Just like the trigonometric functions, you can calculate the value of sinh(x),
cosh(x), and tanh(x) directly. The rest of the values can be calculated using
various relations among these three values.
There are also other functions like asinh(x), acosh(x), and atanh(x), which can
be used to calculate the inverse of the corresponding hyperbolic values
Hyperbolic functions
Time Functions in Python
What is Tick?
Time intervals are floating-point numbers in units of seconds. Particular
instants in time are expressed in seconds since 00:00:00 hrs January 1,
1970(epoch).
There is a popular time module available in Python which provides
functions for working with times, and for converting between
representations. The function time.time() returns the current system
time in ticks since 00:00:00 hrs January 1, 1970(epoch).
Epoch:- a particular period of time in history or a person's life
Time Functions in Python
• gmtime(sec) :- This function returns a structure with 9 values each representing
a time attribute in sequence. It converts seconds into time attributes(days,
years, months etc.) till specified seconds from epoch. If no seconds are
mentioned, time is calculated till present.
• asctime(“time”) :- This function takes a time attributed string produced by
gmtime() and returns a 24 character string denoting time.
• ctime(sec) :- This function returns a 24 character time string but takes seconds
as argument and computes time till mentioned seconds. If no argument is
passed, time is calculated till present.
• sleep(sec) :- This method is used to halt the program execution for the time
specified in the arguments
Python Datetime Module
A date in Python is not a data type of its own, but we can import
a module named datetime to work with dates as date objects.
Example:
Import the datetime module and display the current date:
Python Random Module
Python Random module is an in-built module of Python which is used
to generate random numbers. These are pseudo-random numbers
means these are not truly random. This module can be used to perform
random actions such as generating random numbers, print random a
value for a list or string, etc.
Example: Printing a random value from a list
Python Random Module
he randrange() method returns a randomly selected
element from the specified range.
Syntax
random.randrange(start, stop, step)
Return number between 3(included) and 9 (not included )
Python Packages
Suppose you have developed a very large application that includes many modules.
As the number of modules grows, it becomes difficult to keep track of them all if they are
dumped into one location. This is particularly so if they have similar names or
functionality.
You might wish for a means of grouping and organizing them.
Packages allow for a hierarchical structuring of the module namespace using dot
notation. In the same way that modules help avoid collisions between global variable
names, packages help avoid collisions between module names.
Creating a package is quite straightforward, since it makes use of the operating system’s
inherent hierarchical file structure. Consider the following arrangement:
In the same way, a package in Python takes the concept of the modular approach to next
logical level.
As you know, a module can contain multiple objects, such as classes, functions, etc. A
package can contain one or more relevant modules.
Physically, a package is actually a folder containing one or more module files
External Modules
What are External Modules?
External modules are collections of pre-written code that offer additional functions,
classes, or methods not available in Python's standard library
List of Most Popular Python External Modules
Data Analysis and Manipulation:
•pandas: Provides high-performance, easy-to-use data structures and data analysis
tools.
•numpy: Fundamental package for numerical computations in Python.
External Modules
Machine Learning and Artificial Intelligence:
•scikit-learn: Machine learning library featuring various algorithms and tools.
•TensorFlow: Open-source machine learning framework developed by Google.
•PyTorch: An open-source deep learning platform by Facebook.
4. Data Visualization:
•matplotlib: Comprehensive library for creating static, animated, and interactive
visualizations.
•seaborn: Data visualization library based on matplotlib; provides a higher-level
interface for drawing attractive and informative statistical graphics.
5. Web Scraping:
•BeautifulSoup: Library for pulling data out of HTML and XML documents.
•Scrapy: An open-source and collaborative web crawling framework.
Using External Modules
Pip install module_name
Example
LET’S PRACTICE
SOME EXAMPLES
Practical Examples (I)
Let’s open the following notebook:
Notebook Name: File_Handling.ipynb
70
References
•Python Tutorial | Learn Python Programming
- GeeksforGeeks
•Python Tutorial (tutorialspoint.com
https://www.w3schools.com/Python/module_statistics.asp
https://www.w3schools.com/python
11
0
THANK YOU!

More Related Content

PDF
ch 2. Python module
PPTX
pythontraining-201jn026043638.pptx
PPTX
Python training
PPTX
CPP homework help
ODP
James Jesus Bermas on Crash Course on Python
PPTX
Pa2 session 1
PDF
Astronomy_python_data_Analysis_made_easy.pdf
PDF
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ch 2. Python module
pythontraining-201jn026043638.pptx
Python training
CPP homework help
James Jesus Bermas on Crash Course on Python
Pa2 session 1
Astronomy_python_data_Analysis_made_easy.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdf

Similar to Introduction to Python_for_machine_learning.pdf (20)

PDF
Educational Objectives After successfully completing this assignmen.pdf
PPTX
Docketrun's Python Course for beginners.pptx
PPTX
Python introduction
PPTX
Functional Programming.pptx
PPTX
libraries in python using different .pptx
PPTX
Mastering Python lesson 4_functions_parameters_arguments
PPT
MATLAB-tutorial for Image Processing with Lecture 3.ppt
PPTX
Basic Python Programming: Part 01 and Part 02
PDF
Functions-.pdf
PPT
Object-Oriented Programming Using C++
PDF
Lec16-CS110 Computational Engineering
PDF
Python made easy
PPTX
FILE AND OBJECT<,ITS PROPERTIES IN PYTHON
PDF
Python cheat-sheet
PPT
An Overview Of Python With Functional Programming
PDF
advanced python for those who have beginner level experience with python
PDF
Advanced Python after beginner python for intermediate learners
PPTX
Python Tutorial Part 1
PPTX
Python for data analysis
PPT
asdf adf asdfsdafsdafsdfasdfsdpy llec.ppt
Educational Objectives After successfully completing this assignmen.pdf
Docketrun's Python Course for beginners.pptx
Python introduction
Functional Programming.pptx
libraries in python using different .pptx
Mastering Python lesson 4_functions_parameters_arguments
MATLAB-tutorial for Image Processing with Lecture 3.ppt
Basic Python Programming: Part 01 and Part 02
Functions-.pdf
Object-Oriented Programming Using C++
Lec16-CS110 Computational Engineering
Python made easy
FILE AND OBJECT<,ITS PROPERTIES IN PYTHON
Python cheat-sheet
An Overview Of Python With Functional Programming
advanced python for those who have beginner level experience with python
Advanced Python after beginner python for intermediate learners
Python Tutorial Part 1
Python for data analysis
asdf adf asdfsdafsdafsdfasdfsdpy llec.ppt
Ad

Recently uploaded (20)

PPTX
STERILIZATION AND DISINFECTION-1.ppthhhbx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
IB Computer Science - Internal Assessment.pptx
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
Introduction to Knowledge Engineering Part 1
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PDF
Business Analytics and business intelligence.pdf
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PDF
annual-report-2024-2025 original latest.
PPT
Quality review (1)_presentation of this 21
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PDF
Introduction to the R Programming Language
PDF
Introduction to Data Science and Data Analysis
PDF
Fluorescence-microscope_Botany_detailed content
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Introduction to machine learning and Linear Models
STERILIZATION AND DISINFECTION-1.ppthhhbx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
IB Computer Science - Internal Assessment.pptx
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Introduction to Knowledge Engineering Part 1
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Business Analytics and business intelligence.pdf
Miokarditis (Inflamasi pada Otot Jantung)
oil_refinery_comprehensive_20250804084928 (1).pptx
annual-report-2024-2025 original latest.
Quality review (1)_presentation of this 21
Business Ppt On Nestle.pptx huunnnhhgfvu
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Introduction to the R Programming Language
Introduction to Data Science and Data Analysis
Fluorescence-microscope_Botany_detailed content
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
STUDY DESIGN details- Lt Col Maksud (21).pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Introduction to machine learning and Linear Models
Ad

Introduction to Python_for_machine_learning.pdf