2. 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
3. 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
4. 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
12. Basic I/P and O/P Operation :
O/P Function :
•Print to the screen what you write !
Hello world
13. 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
14. 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
15. Syntax:
Python Identifier:a name used to identify a
Case Sensitive
Variable function,class, module or other object
Python is Language
40. 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.
59. 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
78. 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
80. 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
82. 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.
83. 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
84. 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)
86. 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
88. 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
90. 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
91. 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
92. 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:
93. 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
94. 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 )
95. 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
96. 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.
97. 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.