Python
Fundamentals
Tuesday, July 22, 2025 1
Contents
• Introduction To Programming
• What is Python?
• Why Python?
• Data Types & Variables
• Operations
• Casting
• Take input from user
• Lists
• Tuples
• Dictionaries
• Sets
2
Contents
• Conditions
• Loops
• Functions
• Functions with parametars
• Important Libiraries
• Numpy
• Matplotlib
• Pandas
• Seaborn
• Scipy
3
Agenda
• Introduction To Programming
• What is Python?
• Why Python?
• Data Types & Variables
• Operations
• Casting
• Take input from user
4
Introduction To Programming
• Programming is the art of giving instructions to a computer to perform specific tasks. In the context
of data analysis, programming allows us to manipulate, analyze, and visualize data effectively.
• Python, a versatile and beginner-friendly programming language, has gained immense popularity in
the field of data analysis due to its simplicity, readability, and powerful libraries.
5
What is Python?
• Python is an interpreted, object-oriented, high-level programming language with dynamic
semantics.
• Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it
very attractive for Rapid Application Development, as well as for use as a scripting or glue language
to connect existing components together.
6
Why Python?
• Why Python? Python has emerged as the go-to language for data analysis and data science due to
several factors:
• Versatility: Python can handle a wide range of tasks, from simple scripting to complex data
manipulation and machine learning.
• Rich Ecosystem: Python boasts a vast collection of libraries specialized for data analysis, such
as Pandas, NumPy, and Matplotlib, making data manipulation and visualization convenient.
• Community Support: Python has a large and active community of developers, which means
extensive documentation, tutorials, and community-driven resources are readily available.
• Python's flexibility and accessibility make it an ideal choice for beginners venturing into the world of
data analysis.
7
Data Types
Python – Data
Types
Sequence
Numeric Dictionary Boolean Set
Type
Complex
Integer Float String List Tuple
Number
8
Data Types: Numeric
•Integers – This value is represented by int class. It contains positive or negative
whole numbers (without fractions or decimals). In Python, there is no limit to how
long an integer value can be.
•Float – This value is represented by the float class. It is a real number with a
floating-point representation. It is specified by a decimal point. Optionally, the
character e or E followed by a positive or negative integer may be appended to
specify scientific notation.
•Complex Numbers – A complex number is represented by a complex class. It is
specified as (real part) + (imaginary part)j. For example – 2+3j
9
Data Types: Sequence
String
Strings in Python are arrays of bytes representing Unicode characters. A string is a collection of one or
more characters put in a single quote, double-quote, or triple-quote. In Python, there is no character data
type Python, a character is a string of length one. It is represented by str class.
string = ‘Hello world!’
print(string)
10
Data Types: List
List
Lists are just like arrays, declared in other languages which is an ordered collection of
data. It is very flexible as the items in a list do not need to be of the same type.
List = [“Ahmed", “Mohamed", “Sara"] Output:
print("\nList containing multiple values: ")
Ahmed
print(List[0]) Sara
print(List[2])
11
Data Types: Tuple
Tuple
Just like a list, a tuple is also an ordered collection of Python objects. The only
difference between a tuple and a list is that tuples are immutable i.e. tuples cannot
be modified after it is created. It is represented by a tuple class.
tuple1 = ([1, 2, 3, 4, 5])
print("First element of tuple") Output:
print(tuple1[0])
First element of tuple
print("\nLast element of tuple")
1
print(tuple1[-1]) Last element of tuple
print("\nThird last element of tuple") 5
Third last element of tuple
print(tuple1[-3]) 3
12
Data Types: Boolean
Tuple
Boolean objects that are equal to True are truthy (true), and those equal to False are
falsy (false).
Output:
print(type(True))
print(type(False)) <class 'bool'>
<class 'bool'>
13
Data Types: Set
Set
A Set is an unordered collection of data types that is iterable, mutable, and has no
duplicate elements. The order of elements in a set is undefined though it may consist
of various elements.
Output:
set =([1, 2, ‘Ahmed', 4, ‘Sara', 6])
print("\nSet with the use of Mixed Values")
Set with the use of Mixed Values
print(set) {1, 2, 4, 6, ‘Ahmed’, Sara'}
14
Data Types: Dictionary
Dictionary
A dictionary in Python is an unordered collection of data values, used to store data
values like a map, unlike other Python Data Types that hold only a single value as an
element, a Dictionary holds a key: value pair. Key-value is provided in the dictionary
to make it more optimized. Each key-value pair in a Dictionary is separated by a
colon : , whereas each key is separated by a ‘comma’.
student = { "name": "John Doe", "age": 20, "courses": Output:
["Math", "Science"], "grade": "A" }
name = student["name"]
John Doe
print(name) Not Available
address = student.get("address", "Not Available")
print(address)
15
Variables
• Definition of Variables
• In programming, variables are containers for storing data values. These values can be numbers, strings, lists, or
other data types.
• Variables allow us to label and manipulate data within a program, making it easier to work with and
understand.
• Declaring Variables in Python
• In Python, variables are created by assigning a value to a name using the "=" (assignment) operator.
• Python is dynamically typed, meaning you don't need to specify the data type of a variable explicitly. Python
infers the data type based on the assigned value.
• Variable Naming Conventions
• Variable names in Python can contain letters, numbers, and underscores, but they cannot start with a number.
• It's good practice to use descriptive and meaningful names for variables to enhance code readability.
• Variable names should be written in lowercase letters, with words separated by underscores (snake_case).
16
Variables
• Definition of Variables
• In programming, variables are containers for storing data values. These values can be numbers, strings, lists, or
other data types.
• Variables allow us to label and manipulate data within a program, making it easier to work with and
understand.
• Declaring Variables in Python
• In Python, variables are created by assigning a value to a name using the "=" (assignment) operator.
• Python is dynamically typed, meaning you don't need to specify the data type of a variable explicitly. Python
infers the data type based on the assigned value.
• Variable Naming Conventions
• Variable names in Python can contain letters, numbers, and underscores, but they cannot start with a number.
• It's good practice to use descriptive and meaningful names for variables to enhance code readability.
• Variable names should be written in lowercase letters, with words separated by underscores (snake_case).
17
Variables
Examples
Example 1: Example 2:
age = 25 temperature_celsius = 20.5
name = "John" is_raining = True
Print(name) Print(temperature_celsius)
print(age) print(is_raining)
Output: Output:
John 20.5
25 True
18
Operations
• Basic Operations in Python
• Python supports various types of operations, which are essential for manipulating data and controlling program
flow. These operations include:
• Arithmetic Operations:
• Arithmetic operations involve mathematical calculations such as addition, subtraction, multiplication, division,
and exponentiation.
Example
Output: 15
5
50
2.0
100000
19
Operations
• Comparison Operations:
• Comparison operations are used to compare values and determine their relationships, such as equality,
inequality, greater than, less than, etc.
Example:
Output:
False
True
False
20
Operations
• Logical Operations:
• Logical operations are used to perform logical computations and make decisions based on logical conditions.
Example:
Output:
False
True
21
Let’s Practice
22
Practice
• Question 1:
• Write a Program To Calculate an are of rectangle (area = L x W)
Ans:
23
Practice
• Question 2:
• Write a program that reads the radius of a circle and calculates the area and circumference then prints the
results.
Ans:
24
Casting
• What is Casting?
• Casting refers to the process of converting a variable from one data type to another. In Python, casting allows us
to change the data type of a variable as needed during program execution.
• Types of Casting in Python
• There are two types of casting in Python:
• Implicit Casting: Automatic conversion of data types by Python based on context.
• Explicit Casting: Manual conversion of data types using built-in functions like int() , float() , str(),etc.
25
Taking Input From User
• In Python, you can prompt the user to enter data during program execution using the input() function.
• The input() function reads a line of text entered by the user from the keyboard and returns it as a string.
Note that the input is always of type str, which is
important if you want the user to enter numbers.
Therefore, you need to convert the str before trying to
use it as a number
26
Operations
• Summary Question:
Write a program that take two integers from the user and print the results of this equation: Result = ((num1 + num2) * 3) – 10
Ans:
27
Any Questions ?
28
Thank You ♥♥
29