Core Python ESD Final Draft
Core Python ESD Final Draft
Contents
1. Introduction to Python
2. Data types in Python
3. Operators in Python
4. Input and Output
5. Arrays in Python
6. Strings and Characters in Python
7. Importing Packages and Modules
8. NumPy Arrays
9. DataFrames
10. Jupyter/Spyder
Introduction
1. Python is an interpreter-based language, which
allows execution of one instruction at a time.
2. Extensive basic data types are supported e.g.
numbers (floating point, complex, and
unlimited-length long integers), strings (both
ASCII and Unicode), lists, and dictionaries.
3. Variables can be strongly typed as well as
dynamic typed.
4. Supports object-oriented programming
concepts such as class, inheritance, objects,
module, namespace etc.
5. Cleaner exception handling support.
6. Supports automatic memory management.
Interpreter-based
https://www.youtube.com/watch?v=I1f45REi3k4
Dynamic Typed
https://hackernoon.com/i-finally-understand-static-vs-
dynamic-typing-and-you-will-too-ad0c2bd0acc7
Exception Handling
https://stackify.com/application-exception-vs-error-
difference/
Applications Areas
1. Data Science
2. Machine Learning
3. Web Development
4. Image Processing
5. Internet of Things (IoT)
6. Android Apps, etc.
Data Types in Python
a. String
b. List
c. Tuples
4. Dictionary
Data Types in Python
Numbers (Numeric Types -- int,
float, complex)
• Number stores numeric values. Python creates
Number objects when a number is assigned to a
variable.
• For example;
• a = 3 , b = 5 #a and b are number objects
Numbers (Numeric Types -- int,
float, complex)
• Python supports 3 types of numeric data.
Output:
Exercise 2 (complex numbers)
Exercise 3
Guess the output
Exercise 4
What is the output of the below code?
num = 10
num2 = 5
num2 *= num1
print (num2)
Output: 50
Exercise 5
radius=5
area = 3.14 * (radius * radius)
print("Area of a Circle is :", area)
Assignment - 1 Code
radius=5
area = 3.14 * (radius * radius)
print("Area of a Circle is :", area)
None: Class NoneType
Example:
None: Interesting Points
Try it out:
print "\"\"\"\"\""
Operations on Strings
Concatenation:
Continued..
Repetition:
Check existence of a character or
a sub-string in a string
- The keyword in is used for this.
- For example: If there is a text India won the
match and you want to check if won exist in it or
not.
TRY IT OUT!
Converting String to Int or Float
data type and vice versa
Slicing
First let's get familiar with its usage syntax:
string_name[starting_index : finishing_index :
character_iterate]
- String_name is the name of the variable holding
the string.
- starting_index is the index of the beginning
character which you want in your substring.
- finishing_index is one more than the index of the
last character that you want in your substring.
- character_iterate: To understand this, let us
consider that we have a string Hello Brother!, and
we want to use the slicing operation on this string
to extract a substring. (continued..)
Slicing continued..
- str[0:10:2] means, we want to
extract a substring starting from the
index 0 (beginning of the string), to
the index value 10, and the last
parameter means, that we want
every second character, starting
from the starting index. Hence in
the output we will get, HloBo.
- H is at index 0, then leaving e, the
second character from H will be
printed, which is l, then skipping the
second l, the second character from
the first l is printed, which is o and
so on.
String Methods
1. Capitalize
2. Lowercase
3. Uppercase
4. Swapcase
5. Title
6. Length
7. Index
8. Count
9. Starts with and Ends with
Example - String Methods
Solution - String Methods
Assignment - 2
Length Extend
Append Reverse
Count Sort
Sequence
Examples on List Functions and
Methods
1. Create two lists.
2. Find the length of a List.
3. Append both the lists.
4. Count the occurrence of a item in the list.
5. Extend a specific list.
6. Reverse a specific list.
7. Sort the list created.
8. Convert a list in the form of a tuple.
Solution - Example
Solution - Example
Tuples
Solution:
1 5 10
Assignment - 4 - Dictionary
2. Display
the following output using dictionary
methods, string and print function.
Solution - Assignment - 4
Assignment - 5
1. Create 5 list and assign data to it as shown
below. (Emp, Dept1, Dept2, HOD_CS, HOD_IT)
2. Write a python code to display the following
output.
Assignment 5 - Solution
Operators in Python
● Operators are used for performing various types
of operations on any given operand(s).
● In python, we have 7 different types of operators,
they are:
○ Arithmetic Operators
○ Comparison Operators
○ Assignment Operators
○ Logical Operators
○ Bitwise Operators
○ Membership Operators
○ Identity Operators
● While the first five are commonly used operators
the last two i.e. Membership and Identity.
Arithmetic Operators
Arithmetic operators are the operators used for
performing arithmetic operations on numeric
operands like division, subtraction, addition etc.
Comparison Operators
Assignment Operators
principal=7800
rate_of_interest=7.7
time=26
interest=0
What is the
conclusion?
Summarising 1D arrays