How To Make The Best Use Of Live Sessions
• Please log in 10 mins before the class starts and check your internet connection to avoid any network issues during the LIVE
session
• All participants will be on mute, by default, to avoid any background noise. However, you will be unmuted by instructor if
required. Please use the “Questions” tab on your webinar tool to interact with the instructor at any point during the class
• Feel free to ask and answer questions to make your learning interactive. Instructor will address your queries at the end of
on-going topic
• Raise a ticket through your LMS in case of any queries. Our dedicated support team is available 24 x 7 for your assistance
• Your feedback is very much appreciated. Please share feedback after each class, which will help us enhance your learning
experience
Copyright © edureka and/or its affiliates. All rights reserved.
Copyright © edureka and/or its affiliates. All rights reserved.
Course Outline
Introduction to Python Dimensionality Reduction
Sequences and File Operations Supervised Learning - II
Deep Dive-Functions, OOPS,
Modules, Errors and Exceptions Unsupervised Learning
Introduction to Numpy, Pandas Association Rules Mining and
and Matplotlib Recommendation Systems
Data Manipulation Reinforcement Learning
Introduction to Machine Learning
with Python Time Series Analysis
Supervised Learning - I Model Selection and Boosting
Copyright © edureka and/or its affiliates. All rights reserved.
Introduction to Python
Topics
The topics covered in this module are:
▪ Need of Programming
▪ Companies using Python
▪ Applications where Python is Used
▪ Python Interpreter
▪ Values, Types, Variables
▪ Operands and Expressions
▪ Write your First Python Program
▪ Command Line Arguments
Copyright © edureka and/or its affiliates. All rights reserved.
Objectives
After completing this module, you should be able to:
▪ Define Python
▪ Understand why Python is Popular
▪ Know where Python is used in Applications
▪ Setup Python Environment
▪ Discuss Python Interpreter
▪ Define Values, Types, Variables
▪ Understand Operands and Expressions
▪ Write your First Python Program
▪ Work with Conditional Statements and Loops
▪ Understand Command Line Parameters and Flow Control
Need of Programming
Copyright © edureka and/or its affiliates. All rights reserved.
Dave what is
the need of
Programming?
Let me tell you
few scenarios
to explain that
Copyright © edureka and/or its affiliates. All rights reserved.
Course Management System
John’s job is to film and edit courses for a website
John
Copyright © edureka and/or its affiliates. All rights reserved.
Course Management System
John films and edits courses for a website
John
Copyright © edureka and/or its affiliates. All rights reserved.
Course Management System
In the process of preparing a course, John needs to deal with many different files
Video Files Audio Files Motion Graphics
He creates a set of folders to organize these materials by course, lesson and type of file
Physics Chemistry Maths
Copyright © edureka and/or its affiliates. All rights reserved.
Course Management System – Problem Statement
Creating these
folders take a Physics
lot of time
John wants something
to automate this task,
and save a lot of time
Chemistry
He was creating these
folders manually
Maths
Copyright © edureka and/or its affiliates. All rights reserved.
Hospital Management System
Annie is a receptionist in a hospital
Annie
Copyright © edureka and/or its affiliates. All rights reserved.
Hospital Management System – Problem Statement
She gets annoyed because, she has to give hard copy of the report to the patients
Copyright © edureka and/or its affiliates. All rights reserved.
Hospital Management System
She wants to create a system which will link Patient’s report to their given Aadhar Card Number
Annie
Copyright © edureka and/or its affiliates. All rights reserved.
Now, I will tell
you how John
and Annie solved
their problems
Copyright © edureka and/or its affiliates. All rights reserved.
Solution - 1
John learnt programming and designed a system, which automatically creates
folders, name of the course, number of lessons at the end of the course
John
Copyright © edureka and/or its affiliates. All rights reserved.
Solution - 2
Annie wrote a Program to design a system, in which a patient has to enter
his/her Aadhar Card Number and reports will be linked to his number
Annie
Copyright © edureka and/or its affiliates. All rights reserved.
Need of Programming
To develop application and games Automate time consuming tasks
Provide proper environment for Advances ability to develop real time
Programming algorithms
Keeps track of historic data and analyses it Improve customized your existing system
Provides better experience to end users Help in stream lining of Process
Copyright © edureka and/or its affiliates. All rights reserved.
Advantages of Programming
With Out Computer Programs With Computer Programs
Communicate with others: 3-4 days for sending a letter to some Less than 1-minute to send an email to any place in the world at
one even in the same district and it costs money no cost
Booking Railway Tickets: Stand in really long queues. Can reserve Can book tickets from anywhere to anywhere, sitting at home
railway tickets only for the quota of that station. Even if other
stations quota is not filled, we can not reserve the tickets. Can
only book tickets from that station and can not book return
tickets
Sending money from parent to the child studying in a The money transfer is almost instant and money can be
college: This involves the parent going to the bank for the DD, withdrawn from any ATM
send it to the student by post, student submitting the DD in the
bank, wait for the DD to clear and withdraw the money by
showing the passbook and filling an withdrawal form
Seat allocation in engineering college: Go to the counseling Have lots of time to research the colleges, decide upon the
center far away from your town, wait for hours together for your colleges and branches, review them multiple people and submit
turn, but make the decision of which college and branch to it online with peace of mind
choose in less than 5 minutes
Copyright © edureka and/or its affiliates. All rights reserved.
Why Python?
Copyright © edureka and/or its affiliates. All rights reserved.
I have heard
there are a lot
of Programming
languages?
Well, I will discuss
few of the most
famous ones
Copyright © edureka and/or its affiliates. All rights reserved.
Different Programming Languages
C++ Matlab HTML
Python
Scala Java PHP
Copyright © edureka and/or its affiliates. All rights reserved.
Dave tell me which
Programming language
should I start with
It has to be Python,
let me give you
enough reasons to
believe that
Copyright © edureka and/or its affiliates. All rights reserved.
Why Python?
Simple and Easy to Learn
Python is simple and easy to learn, read & write
Free and Open Source
Python is an example of a FLOSS (Free/Libre and Open Source Software)
which means one can freely distribute copies of this software, read it's
source code, modify it, etc.
Copyright © edureka and/or its affiliates. All rights reserved.
Why Python?
High-level Language
One does not need to bother about the low-level details like
memory allocation, etc. while writing a Python script
Portable
Supported by many platforms like Linux, Windows, FreeBSD, Macintosh,
Solaris, BeOS, OS/390, PlayStation, Windows CE, etc.
Copyright © edureka and/or its affiliates. All rights reserved.
Why Python?
Procedure
Supports different Programming Paradigm Oriented
Python supports procedure-oriented programming as well as object- Object
oriented programming Oriented
Extensible
Python code can invoke C and C++ libraries, can be called from and C++ programs,
can integrate with Java and .NET components
Copyright © edureka and/or its affiliates. All rights reserved.
Why Python?
Improved Programmer’s productivity Extensive Support Libraries
Integration Feature Productivity
Robust Program Portability
Interactive, Interpreted and Dynamic Object Oriented Language
Copyright © edureka and/or its affiliates. All rights reserved.
Companies Using Python
Copyright © edureka and/or its affiliates. All rights reserved.
Python is also
widely used by a lot
of companies, I will
tell you about few
giants
Copyright © edureka and/or its affiliates. All rights reserved.
Who is using Python?
Copyright © edureka and/or its affiliates. All rights reserved.
Applications Where Python Is Used
Copyright © edureka and/or its affiliates. All rights reserved.
Now, the best part
about Python - it’s
Applications
Copyright © edureka and/or its affiliates. All rights reserved.
Python Applications
Copyright © edureka and/or its affiliates. All rights reserved.
Are there enough
jobs in the market
for Python related
roles To prove that, I
will show you few
stats
Copyright © edureka and/or its affiliates. All rights reserved.
Job Trends
Job trends from Indeed.com shows remarkable increase in the demand of Python related jobs
Copyright © edureka and/or its affiliates. All rights reserved.
Python Graph on Google Trends
Copyright © edureka and/or its affiliates. All rights reserved.
Python Interpreter
Copyright © edureka and/or its affiliates. All rights reserved.
Python Interpreter
▪ Python Interpreter is a program that reads and executes code
▪ This includes source code, pre-compiled code and scripts
▪ Example: help(‘for’)
Copyright © edureka and/or its affiliates. All rights reserved.
Getting Started With Python in Command Prompt
You need to write python in command prompt for automatic installation
of all packages. Once this is done, you can write your code
Copyright © edureka and/or its affiliates. All rights reserved.
Comments and Literals
Comments: Any text to the right of the # symbol is mainly used as notes for the readers. Statements on right
side of # does not get executed. It gives more information about function
▪ Bulk Comments: Enclose the code in triple quoted strings (“””)
▪ Literal Constants: Any number or character, or set of characters
Copyright © edureka and/or its affiliates. All rights reserved.
Indentation
No braces to indicate Blocks of code are The number of spaces Leading whitespace at
blocks of code for class denoted by line in the indentation is the beginning of a logical
and function indentation, which is variable, but all line is used to compute
definitions or flow rigidly enforced statements within the the indentation level of
control block must be the line, which in turn, is
indented the same used to determine the
amount grouping of statements
Copyright © edureka and/or its affiliates. All rights reserved.
Python Code Execution
Source Byte Code PVM
The structured code is The code is converted into
The Byte codes are
written and saved with Byte code for machine to
executed
.py extension understand
Copyright © edureka and/or its affiliates. All rights reserved.
Demo: Creating “Hello World” Program
Copyright © edureka and/or its affiliates. All rights reserved.
Output
Every character in Python should be
Output after running new.py
enclosed within single or double quotes
print(‘Hello World’)
print("Welcome to Edureka")
Copyright © edureka and/or its affiliates. All rights reserved.
Variables
Copyright © edureka and/or its affiliates. All rights reserved.
Identifier
▪ A Python Identifier is a name used to identify a variable, function, class, module or other object
▪ An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters,
underscores and digits (0 to 9)
▪ Python is a case sensitive programming language
▪ Python does not allow special characters such as @, $ and % within identifiers
Copyright © edureka and/or its affiliates. All rights reserved.
Identifiers – Naming Conventions
Class names start with an uppercase Starting an identifier with a single
letter. All other identifiers start with a leading underscore indicates that the
lowercase letter identifier is private
Starting an identifier with two leading If the identifier also ends with two
underscores indicates a strongly private trailing underscores, the identifier is a
identifier language-defined special name
Copyright © edureka and/or its affiliates. All rights reserved.
Variables
Variables are nothing but reserved memory locations to store values. This means that when you create
a variable you reserve some space in memory
A=16 Memory
A = 16
B = 20 Memory
B=20
C = ‘edureka’
C= ‘edureka’ Memory
Copyright © edureka and/or its affiliates. All rights reserved.
Variables (Contd.)
Consider the below screenshot, it explains how to assign a value to a Variable
Assigning values 10 and edureka! to Right click and click on ‘Run
variables A and B respectively File_name’ to execute the code
A=10
B='edureka!'
print(A,B)
Output
Copyright © edureka and/or its affiliates. All rights reserved.
Standard Data Types
Copyright © edureka and/or its affiliates. All rights reserved.
Standard Data Types
Standard Data Types
Values cannot be Values can be
changed changed
Immutable Data Types Mutable Data Types
Numbers Tuples Lists Sets
Strings Dictionaries
Copyright © edureka and/or its affiliates. All rights reserved.
Immutable Data Types
Numbers Tuples
Strings
Copyright © edureka and/or its affiliates. All rights reserved.
Numeric Data Type – Immutable Data Type
Python supports three different numerical values
Numeric
int ( Signed Integers ) Complex Numbers
Strings
float ( Real Numbers )
In Python you can represent Numbers in multiple ways:
Tuples • Binary
• Octal
• Hexadecimal
Copyright © edureka and/or its affiliates. All rights reserved.
Numeric Data Type – Immutable Data Type
Integer
Numeric
A=10 Float
Strings B=10.65
C=10+6j
Complex
print(A,B,C)
Tuples
Output
Copyright © edureka and/or its affiliates. All rights reserved.
Strings – Immutable Data Type
The continuous set of characters represented within quotation is called as String. Python
Numeric allows for either pairs of single or double quotes. Python does not support a character
type, these are treated as strings of length one
A='Welcome To edureka!' Python cannot
differentiate between
Strings B="Python is Great" single and double quotes
print(A)
print(B)
Tuples
Output
Copyright © edureka and/or its affiliates. All rights reserved.
Tuples – Immutable Data Type
Tuples consists of a number of values separated by comma. It is enclosed within parenthesis
Numeric
A Tuple can have objects
of different data types,
Strings A=(1,2,3.15,'edureka!') unlike Arrays in ‘C’
print(A)
Tuples
Output
Copyright © edureka and/or its affiliates. All rights reserved.
Mutable Data Types
Lists Sets
Dictionaries
Copyright © edureka and/or its affiliates. All rights reserved.
Lists - Mutable Data Type
List is an ordered set of elements enclosed within square brackets. The main
differences between Lists and Tuples are:
Lists
• Lists are enclosed in brackets[] and Tuples are enclosed within parenthesis()
• Lists are Mutable and Tuples are Immutable
• Tuples are faster than Lists
Dictionaries
Lists are enclosed within
A=[1,2,3.15,'edureka!’]
square brackets
print(A)
Sets
Output
Copyright © edureka and/or its affiliates. All rights reserved.
Dictionaries - Mutable Data Type
Dictionaries contain key value pairs. Each key is separated from its value by a colon (:),
Lists the items are separated by comma, and the whole thing is enclosed within curly braces
Keys
Dictionaries
A={'Age':24, 'Name':'John'}
print(A)
Values
Sets
Output
Copyright © edureka and/or its affiliates. All rights reserved.
Sets - Mutable Data Type
A set is an unordered collection of items. Every element is unique. A set is created by
Lists placing all the items (elements) inside curly braces {}, separated by comma.
Every element in a
Set has to be unique
Dictionaries
A={1,2,3,3}
print(A)
Sets
Output – Notice that 3
has appeared only once
You can also create a Set by calling an in built-function ‘set’
Copyright © edureka and/or its affiliates. All rights reserved.
Python Operators
Copyright © edureka and/or its affiliates. All rights reserved.
Operators
Operators are the constructs which can manipulate the values of the Operands. Consider the
expression 2 + 3 = 5, here 2 and 3 are Operands and + is called Operator
Arithmetic Comparison Bitwise Membership
Assignment Logical Identity
Copyright © edureka and/or its affiliates. All rights reserved.
Arithmetic Operators
Arithmetic
Addition a+b
Assignment
Subtraction a–b
Comparison
Multiplication a*b
Logical Division a/b
Bitwise Modulus a%b
Exponent a ** b
Identity
Floor Division a // b
Membership
Copyright © edureka and/or its affiliates. All rights reserved.
Assignment Operators
Arithmetic
Assigns value from right to left a=b
Assignment
a=a+b a+=b
Comparison
a=a-b a-= b
Logical
a = a*b a*=b
Bitwise
a = a/b a /= b
Identity
a = a**b a** = b
Membership a//=b
a=a//b
Copyright © edureka and/or its affiliates. All rights reserved.
Comparison Operators
Arithmetic
Equal To a == b
Assignment
Not Equal To
Comparison a != b
Greater Than a>b
Logical
Less Than a<b
Bitwise
Greater Than Equal To a >= b
Identity
Membership Less Than Equal To a <= b
Copyright © edureka and/or its affiliates. All rights reserved.
Logical Operators
Arithmetic
Assignment a and b Returns a, if a is False, b otherwise
Comparison
a or b Returns b, if b is False, a otherwise
Logical
Bitwise
not a Returns True, if a is False, False otherwise
Identity
Membership
Copyright © edureka and/or its affiliates. All rights reserved.
Bitwise Operators
Arithmetic
Binary AND a&b
Assignment
Binary OR a|b
Comparison
Logical
Binary XOR a^b
Bitwise Binary NOT a~b
Identity Binary Left Shift a <<
Membership Binary Right Shift a >> b
Copyright © edureka and/or its affiliates. All rights reserved.
Identity Operators
Arithmetic
Evaluates to TRUE, if the variables on either side of the
is
Assignment operator point to the same object and FALSE otherwise
Comparison
Logical is not Evaluates to FALSE, if the variables on either side of the
operator point to the same object and TRUE otherwise
Bitwise
Identity
Membership
Copyright © edureka and/or its affiliates. All rights reserved.
Membership Operators
Arithmetic
Assignment
in Evaluates to TRUE, if it finds a variable in the specified
Comparison sequence and FALSE otherwise
Logical
Bitwise not in Evaluates to TRUE, if it does not find a variable in the
specified sequence and FALSE otherwise
Identity
Membership
Copyright © edureka and/or its affiliates. All rights reserved.
Conditional Statements
Copyright © edureka and/or its affiliates. All rights reserved.
Conditional Statements
Conditional statements are used to execute a statement
or a group of statements, when some condition is true
If condition is
FALSE
Types of Conditional Statements Condition
If condition is
TRUE
Conditional Code
If Elif Else
Copyright © edureka and/or its affiliates. All rights reserved.
If Elif Else Statements
Copyright © edureka and/or its affiliates. All rights reserved.
If, Elif and Else Statements
Consider the syntax and example below:
Example:
Syntax:
X=10
Y=12
if(X<Y):
print('X is less than Y')
elif(X>Y):
print('X is greater than Y')
else:
print('X and Y are equal')
Copyright © edureka and/or its affiliates. All rights reserved.
Loops
Copyright © edureka and/or its affiliates. All rights reserved.
Loops
A loop statement allows us to execute a statement If condition is
true
or a group of statement multiple times
Types of Loops Conditional
Code
Condition
If condition is
false
While For Nested
Copyright © edureka and/or its affiliates. All rights reserved.
While Loop
“While” loops are known as indefinite or conditional loops. They will keep iterating until certain conditions are
met. There is no guarantee ahead of time regarding how many times the loop will iterate
Syntax:
Copyright © edureka and/or its affiliates. All rights reserved.
While Loop Example
Condition
count=0
while(count<5): Conditional
print(count) Code
count=count+1
print("Good bye!")
Output – Prints all the
integers between 0 and 5
Copyright © edureka and/or its affiliates. All rights reserved.
While Loop Example
Copyright © edureka and/or its affiliates. All rights reserved.
For Loop
▪ “For” loop is a Python loop which repeats a group of statements a specified
number of times. The for loop provides a syntax where the following information
is provided:
− Boolean condition
− The initial value of the counting variable
− Incrementation of counting variable
Copyright © edureka and/or its affiliates. All rights reserved.
For Loop Example
Difference between For and While loop is that, in While loop we don’t know the amount of iterations, where
as in For loop we are aware of how many times the block of code will be executed
fruits=['Banana','Apple','Grapes']
for index in range(len(fruits)):
print(fruits[index])
Copyright © edureka and/or its affiliates. All rights reserved.
For Loop Example
We will be using For loop to write a program that calculates the factorial of any number
Copyright © edureka and/or its affiliates. All rights reserved.
Nested Loops
Nested Loop, basically means a loop inside a loop. It can be a For loop inside a While loop and
vice-versa. It can also be a While loop inside a While loop or For loop inside a For loop
count=1
for i in range(10):
print(str(i)*i)
For loop inside
for j in range(0,i): a For loop
count=count+1
Output
Copyright © edureka and/or its affiliates. All rights reserved.
Nested Loops Example
Copyright © edureka and/or its affiliates. All rights reserved.
Loop Control Statements
▪ Loop control statements change execution from its normal sequence. When execution leaves a scope, all
automatic objects that were created in that scope are destroyed
Control Statement Description
break statement Terminates the loop statement and transfers execution
to the statement immediately following the loop
continue statement Causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating
pass statement The pass statement in Python is used when a
statement is required syntactically but you do not want
any command or code to execute
Copyright © edureka and/or its affiliates. All rights reserved.
Example - Loop Control Statements
for i in range(10,50): for j in range(1,11):
for k in range(1,3):
print(i) print(j)
pass
if(i==30): if(j==5):
print("Loop ends here")
break continue
Copyright © edureka and/or its affiliates. All rights reserved.
Command Line Parameters
Copyright © edureka and/or its affiliates. All rights reserved.
Command Line Parameters
▪ It is possible to pass arguments to Python programs when they are executed
▪ The brackets which follow main are used for this purpose
▪ . argv refers to the number of arguments passed, and argv[] is a pointer array which points to
each argument which is passed to main
▪ The Python sys module provides access to any command-line arguments via the sys.argv. This serves two
purposes :
− sys.argv is the list of command-line arguments
− len(sys.argv) is the number of command-line arguments
Copyright © edureka and/or its affiliates. All rights reserved.
Command Line Parameters(Contd.)
▪ Example:
− Consider the following script test.py
#!/usr/bin/python
import sys
print ('Number of arguments:',
len(sys.argv), 'arguments.’ )
print ('Argument List:', str(sys.argv) )
− Now, run above script as follow:
$ python test.py arg1 arg2 arg3
− After running this script, Output will be
Number of arguments: 4 arguments. Argument
List: ['test.py', 'arg1', 'arg2', 'arg3']
Copyright © edureka and/or its affiliates. All rights reserved.
Summary
In this module, you should have learnt:
▪ Why we are using Python over other languages
▪ Python IDEs
▪ Identifiers, Variables
▪ Standard Data types
▪ Operators
▪ Conditional Statements
▪ Loops and Iterations
▪ Command Line Parameters
Copyright © edureka and/or its affiliates. All rights reserved.
Copyright © edureka and/or its affiliates. All rights reserved.
Copyright © edureka and/or its affiliates. All rights reserved.