SlideShare ist ein Scribd-Unternehmen logo
1 von 75
Downloaden Sie, um offline zu lesen
INTRODUCTION TO
PYTHON3 IN 2022
MOHAMMED AMAN NAWAZ
BY ENGANT.COM
PYTHON 3
INTRODUCTION
Introduction To Python 4
Python Installation 13
Python Fundamentals 21
Data Types in Python 30
Flow of Control in Python 39
Python OOPS concepts 47
Python Practice Programs 58
Top 30 Interview Questions 67
Career Guidance 68
1.
2.
3.
4.
5.
6.
7.
8.
9.
10. References 73
Engant.com
A few words of acknowledgment...
First and foremost,
To my highest source of inspiration, the Supreme Speaker
Those words I only channel...
My MOM & DAD!
Then to the true support throughout my career, both
friends and family... you've all been amazing!
And last but not least, to YOU, my dear reader... and my
real reason!
Thank you all...
Namaste!
Copyright © Engant
ALL RIGHTS RESERVED
This eBook or any portion thereof may not be reproduced or used in
any
manner whatsoever without the express written permission of the
copyright
owner and publisher except for the use of brief quotations in
a book review, online, or in print.
First Publication: 2022
Version: 1.00
support@engant.com
BEFORE WE START!
What is Python?
TOPICS COVERED:-
What is Python?
Features Of Python
Why choose Python?
What is Python3?
Chapter-1: What is Python
Engant.com 4
Chapter-1: What is Python
Engant.com 5
What is Python?
Python is a high-level,
interpreted scripting language
developed in the late 1980s by
Guido van Rossum at the
National Research Institute for
Mathematics and Computer
Science in the Netherlands. The
initial version was published at
the alt. sources newsgroup in
1991, and version 1.0 was released
in 1994.
Chapter-1: What is Python
Engant.com 6
Features Of Python
Chapter-1: What is Python
Engant.com
Why Choose Python?
Python is a high-level, interpreted,
interactive and object-oriented
scripting language. Python is
designed to be highly readable. It
uses English keywords frequently
where as other languages use
punctuation, and it has fewer
syntactical constructions than
other languages
7
Chapter-1: What is Python
Engant.com 8
Python is a MUST for students
and working professionals to
become a great Software
Engineer specially when they are
working in Web Development
Domain. I will list down some of
the key advantages of learning
Python:
Chapter-1: What is Python
Engant.com 9
Python is Interpreted −
Python is processed at runtime
by the interpreter. You do not
need to compile your program
before executing it. This is
similar to PERL and PHP.
Python is Interactive − You
can actually sit at a Python
prompt and interact with the
interpreter directly to write
your programs
Chapter-1: What is Python
Engant.com
Python is Object-Oriented −
Python supports the Object-
Oriented style or technique of
programming that encapsulates
code within objects.
Python is a Beginner's
Language − Python is a great
language for beginner-level
programmers and supports the
development of a wide range of
applications from simple text
processing to www browsers to
games
10
Chapter-1: What is Python
Engant.com 11
What is Python3?
Python 3.0 was released in 2008.
Although this version is supposed
to be backward incompatibles,
later on many of its important
features have been backported to
be compatible with version 2.7.This
tutorial gives enough
understanding on Python 3 version
programming language.
Chapter-1: What is Python
Engant.com 12
Applications Of Python
Chapter-2: Python3 Installation & Setup
Engant.com
Python3 Installation &
Setup
TOPICS COVERED:-
DOWNLOADING PYTHON
INSTALLING PYTHON ON
WINDOWS
macOS
LINUX
BEST PYTHON IDE's
1.
2.
3.
13
Engant.com 14
Chapter-2: Python3 Installation & Setup
Downloading Python
1. Go to
www.python.org/downloads/
2. Download Python as per your
system requirement.
Python3 Installation
Engant.com 15
Chapter-2: Python3 Installation & Setup
Installing Python On
Windows
1. Click on Python Releases for
Windows, select the link for the latest
Python 3 Release – Python 3.x.x
2. Scroll to the bottom and select either
Windows x86-64 executable
installer for 64-bit or Windows x86
executable installer for 32-bit
1. Click on Python Releases for
macOS, select the link for the latest
Python 3 Release – Python 3.x.x
2. Scroll to the bottom and select
either Windows x86-64 executable
installer for 64-bit or Windows x86
executable installer for 32-bit
Engant.com
Chapter-2: Python3 Installation & Setup
Installing Python On
macOS
16
1. Open the Ubuntu Software Center
folder
2. Select Developer Tools from the All
Software drop-down list box
3. Double-click the Python 3.3.4 entry
4. Click Install
5. Close the Ubuntu Software Center
folder
Engant.com 17
Chapter-2: Python3 Installation & Setup
Installing Python On
Linux
Engant.com 18
Chapter-2: Python3 Installation & Setup
Best Python IDE's
IDE stands for Integrated Development
Environment which is a Graphical User
Interface where programmers write their
code to produce the final products. An
IDE basically unifies all essential tools
required for software development and
testing. In order to make the best use of
this e-book, install an IDE now and start
implementing the Python concepts as you
learn.
Engant.com 19
Chapter-2: Python3 Installation & Setup
TOP PYTHON IDE's
Pycharm
Jupyter
Notebook
Atom
Engant.com 20
Chapter-2: Python3 Installation & Setup
Level of expertise of the programmer
The type of industry or sector where
Python is being used
Ability to buy commercial versions or
Kind of software being developed
Integration with other languages
Always keep the following points in mind
while choosing the best IDE for Python:
stick to the free ones
Points To Remember while
choosing IDE's
Chapter-3: Python Fundamentals
Engant.com 21
PYTHON
FUNDAMENTALS
TOPICS COVERED:-
Keywords
Identifiers
Variables
Comments
Operators
Function
Function parameter
Keywords are nothing but special
names that are already present in
python. We can use these keywords for
specific functionality while writing a
python program.
#retrieving all keywords
import keyword
keyword.kwlist
#
keyword.iskeyword(' try ')
#this will return true, if the
mentioned name is a keyword
Chapter-3: Python Fundamentals
Engant.com 22
Keywords
Identifiers are user-defined names
that we use to represent variables,
classes, functions, modules, etc.
name = ' engant '
my_identifier = name
#this will return the value of
the identifier provided by the
user
Chapter-3: Python Fundamentals
Engant.com 23
Identifiers
Variables are like a memory location
where you can store a value. This
value, you may or may not change in
the future.
x = 10
y = 20
name = ' engant '
#To declare a Python variable you
only have to assign a value to it
Chapter-3: Python Fundamentals
Engant.com 24
Variables
Chapter-3: Python Fundamentals
Engant.com 25
Single-line or
Multi-line
Comments in programming are the program
coherent statements, that describe what a
block of code means. They are very useful
when you are writing large codes. Comments in
Python start with a # character. Alternatively, at
times, commenting is done using docstrings
(strings enclosed within triple quotes). Python
Comments can be of two types:
#Comments in Python start like this
print("Comments in Python start with a #")
Comments
Chapter-3: Python Fundamentals
Engant.com 26
Operators
Operators in Python are used for
operations
between two values or variables. The
output
varies according to the type of operator
used in the operation. We can call
operators as special symbols or
constructs to manipulate the values of
the operands. Consider the expression
2 + 3 = 5, here 2 and 3 are operands
and + is called operator
Chapter-3: Python Fundamentals
Engant.com 27
A function in Python is a block of code that will execute
whenever it is called. We can pass parameters
in the functions as well. To understand the concept of
functions, let's take an example.
Suppose you want to calculate the factorial of a number.
You can do this by simply executing the logic to calculate
a factorial. But what if you have to do it ten times a day,
writing the same logic, again and again, is going to be a
long task.
Instead, what you can do is, write the logic in a function.
Call that function every time you need to calculate the
factorial. This will reduce the complexity of your code and
save your time as well.
Chapter-3: Python Fundamentals
Engant.com 28
Functions
#declaring a function
def function_name():
#expression
print('abc')
Chapter-3: Python Fundamentals
Engant.com 29
We can pass values in a function using
the parameters. We can use also give
the default values for a parameter in a
function as well.
Function Parameters
#calling a function #default parameter
def my_func(): my_func( )
print('function created')
#this is a function call #userdefined parameter
my_func() my_func('python')
#
def my_func (name = 'engant'):
print(name)
Chapter-4: Data Types
Engant.com 30
DATA TYPES
TOPICS COVERED:-
Numeric
String
List
Tuple
Set
Dictionary
Chapter-4: Data Types
Engant.com
DATA TYPES IN PYTHON
A Variable in python is created as soon as a value is assigned
to it. It does not need any additional commands to declare a
variable in python.
There are certain rules and regulations we have to follow
while writing a variable, lets's take a look at the variable
definition and declaration to understand how we declare a
variable in python
Variables and data types in python as the name suggests are the
values that vary. In a programming language, a variable is a
memory location where you store a value. The value that you have
stored may change in the future according to the specifications
Name= ' engant '
A=10;
B=20;
Name= engant
A=10
B=20
Variable Memory
31
Chapter-4: Data Types
Engant.com 32
According to the properties they possess, there
are mainly six data types in python. Although
there is one more data type range which is
often used while working with loops in python.
DATA TYPES IN PYTHON
Numerical data type holds numerical value. In
numerical data, there are 4 subtypes as well.
Following
are the sub-types of numerical data type:
a. Integers - Integers are used to represent whole
number values
b. Float - Float data type is used to represent decimal
point values
c. Complex Numbers - Complex numbers are used
to represent imaginary values
d. Boolean - Boolean is used for categorical output,
since the output of boolean is either true or false
Chapter-4: Data Types
Engant.com 33
Numeric
1.
String in python are used to represent
Unicode characters values. Python does
not have a character data type, a single
character is considered as a string. We
declare the string values within the single
quotes or double quotes. Indexes & Square
brackets are used to access the values.
Strings are immutable in nature.
Chapter-4: Data Types
Engant.com
2.String
E N A
G N T
0 1 2 3
4
5
4
-1
-2
-3
-4
-5
-6
34
name = 'engant'
name[2]
#this will give you the output as 'n'
name = 'engant'
name.upper()
#this will make the letters to
uppercase
name.lower()
#this will make the letters to
lowercase
name.replace('e') = 'E'
#this will replace the letter 'e' with
'E'
name[1: 4]
#this will return the strings starting at
index 1 until the index 4
Chapter-4: Data Types
Engant.com 35
List is one of the four collection data types that
we have in python. When we are choosing a
collection type, it is important to understand
the functionality and limitations of the
collection. Tuple, set and dictionary are the
other collection data type in Python. A list is
ordered and changeable, unlike strings. We
can add duplicate values as well. To declare a
list, we use the square brackets.
Chapter-4: Data Types
Engant.com 36
3. List
mylist = [10,20,30,40,20,30, 'eng'] mylist.append('engant')
mylist[2:6] #this will add the value at the
#this will get the values end.
from index 2 to 6. .
[6] = 'python' mylist.insert(5, 'data science')
#this will replace the #this will add the value at
value at the index the index 5.
6.
Chapter-4:Data Types
Engant.com 37
A tuple is an ordered data structure whose
values can be accessed using the index values.
It can have duplicate values. To declare a
tuple, we use the round brackets. A tuple is a
read-only data structure and you cannot
modify the size and value of the items of a tuple.
4. Tuple
#declaring a tuple
mytuple = (10,10, 20, 30, 40, 50)
#counting total number of elements
mytuple.count(10)
#to find an item index
mytuple.index(50) #output will be 5
Chapter-4:Data Types
Engant.com 38
A set is a collection that is unordered
& doesn't have any index. To declare
sets in Python, we use curly brackets.
A set does not have any duplicate
values. Even though it will not show
any errors while declaring the set,
the output will only have distinct
values.
5.Set
myset = { 10, 20 , 30 , 40, 50, 50}
#to add a value in a set.
myset.add('engant')
#to add multiple values in a list
myset.update([ 10, 20, 30, 40, 50])
#to remove an item from a set
myset.remove('engant')
6.Dictionary
A dictionary is just like any other
collection array in Python. But they
have key-value pairs. A dictionary is
unordered and changeable. We use
the keys to access the items from a
dictionary. To declare a dictionary,
we use curly brackets.
mydictionary = { 'python' : 'data
science' , 'machine learning' :
'tensorflow' , 'artificial intelligence' :
'keras'}
mydictionary['machine learning']
#this will give the output as
'tensorflow'
mydictionary.get('python')
#this serves the same purpose to
access the value
Chapter-5: Flow Of Control
Engant.com 39
FLOW OF CONTROL
TOPICS COVERED:-
Conditional Statements
If statement
Else statement
Elif statement
Iterative Statements
1.
2.
3.
1. For Loop
2. While Loop
Chapter-5: Flow Of Control
Engant.com 40
FLOW OF CONTROL
Code runs sequentially in any language,
but what if you want to break that
flow such that you are able to add logic
and repeat certain statements such
that your code reduces and are able to
obtain a solution with lesser and
smarter code. After all, that is what coding
is. Finding logic and solutions to
problems and can be done using
Conditional and Iterative statements.
Chapter-5: Flow Of Control
Engant.com 41
Conditional Statements
Conditional statements are executed only if a
certain condition is met, else it is skipped ahead to
where the condition is satisfied. There are various
types of conditional statements supported in Python.
I
F
An if statement is used
to test an expression
and execute certain
statements accordingly.
A program can have
many if statements.
Chapter-5: Flow Of Control
Engant.com 42
An else statement is used
with an if statement. Else
contains the block of a
code that executes if the
conditional expression in
the 'if statement' is FALSE
E
L
S
E
E
L
I
F
The elif statement
allows a number of
expression checks for
TRUE and execute a
block of code as soon as
one of the conditions
returns TRUE
Chapter-5: Flow Of Control
Engant.com 43
if condition :statement
elif condition :statement
else
:statement
This means that if a condition is met,
do something. Else go through the
remaining elif conditions and finally if
no condition is met, execute the else
block. You can even have nested if-else
statements inside the if-else blocks.
a = 15
b = 20
if a == b:
print ( 'They are equal' )
elif a > b:
print ( 'a is larger' )
else :
print ( 'b is larger' )
Example:-
Output:-
b is larger
Chapter-5: Flow Of Control
Engant.com 44
Iterative Statements
Chapter-5: Flow Of Control
Engant.com 45
Loops in Python allow us to execute
a group of statements several times.
Loops can be divided into 2 kinds:
a. Finite: This kind of loop works until a
certain condition is met
b. Infinite: This kind of loop works
infinitely and does not stop ever
Loops in Python or any other languages have to
test the condition and they can be done either
before the statements or after the statements.
They are called:
a. Pre-Test Loops: Where the conditions are tested
first and statements are executed subsequently.
b. Post-Test Loops: Where the statement is
executed at least once and later the condition is
checked
Chapter-5: Flow Of Control
Engant.com 46
FOR
FOR
This loop is used to perform a
certain set of statements for a
given condition and continue
until the condition has failed
WHILE
WHILE
This loop in Python is used to
iterate over a block of code or
statements as long as the test
expression is true.
#syntax
for variable in range: statements
#example
fruits_Basket= ['apple', 'orange',
'pineapple', 'banana']
for fruit in fruits_Basket:
print(fruit, end=',')
#Output is apple, orange,
pineapple, banana
#syntax
while (test expression): statements
#example
second = 5
while second >= 0:
print(second, end='->')
second-=1
print('Blastoff!')
#Output is 5->4->3->2->1->Blastoff!
Chapter-6:Object Oriented Programming
Engant.com 4
OBJECT ORIENTED
PROGRAMMING (OOP) IN
PYTHON
TOPICS COVERED:-
Classes & Objects
Abstraction
Inheritance
Encapsulation
Polymorphism
7
Chapter-6:Object Oriented Programming
Engant.com 48
Object-Oriented Programming (OOP) is a way of
computers using the idea of objects to represent
data and methods. It is also an approach used for
creating neat and reusable code instead of a
redundant one. The program is divided into self-
contained objects or several mini-programs. Every
individual object represents a different part of the
application having its own logic and data to
communicate within itself.
Classes & Objects
class is a collection or you can say it is a blueprint of
objects defining the common attributes and behavior. It
logically groups the data in such a way that code reusability
becomes easy. Class is defined under a " Class " Keyword.
Using a Class, you can add consistency to your programs so
that they can be used in an efficient way. The attributes of a
class are listed below:
#syntax
class EduClass():
Objects are an instance of a class. It is an entity that has
a state and behavior. In a nutshell, it is an
instance of a class that can access the data.
#syntax
class EduClass:
def func (self):
print('Hello')
# create a new EduClass
ob = EduClass()
ob.func()
Chapter-6:Object Oriented Programming
Engant.com 49
a.Class variable is a variable that is shared by all the
different objects/instances of a class.
b. Instance variables are variables that are unique
to each instance. It is defined as a method and
belongs only to the current instance of a class.
c. Methods are also called functions that are defined
in a class and describe the behavior of an object.
Chapter-6:Object Oriented Programming
Engant.com 50
Abstraction
Abstraction is used to simplify complex
reality by modeling classes appropriate to
the problem. Here, we have an abstract
class that cannot be instantiated. This
means you cannot create objects or
instances for these classes. It can only be
used for inheriting certain functionalities
which you call a base class. So you can
inherit functionalities but at the same time,
you cannot create an instance of this
particular class. Let’s understand the
concept of abstract class with an
example.
from abc import ABC, abstractmethod
class Employee (ABC):
@abstractmethod
def calculate_salary (self,sal):
pass
class Developer (Employee):
def calculate_salary(self,sal):
finalsalary= sal*1.10
return finalsalary
emp_1 = Developer()
print(emp_1.calculate_salary(10000))
#OUTPUT - 11000.0
Chapter-6:Object Oriented Programming
Engant.com 51
EXAMPLE:-
Inheritance allows us to inherit attributes and
methods from the base/parent class. This is useful
as we can create sub-classes and get all of the
functionality from our parent class. Then we can
overwrite and add new functionalities without
affecting the parent class. A class that inherits the
properties is known as Child Class whereas a
class whose properties are inherited is known as
Parent class.
Chapter-6:Object Oriented Programming
Engant.com 52
Inheritance
TYPES OF INHERITANCE
Single Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Multiple Inheritance
Chapter-6:Object Oriented Programming
Engant.com 53
EXAMPLE:-
class employee:
num_employee=0
raise_amount=1.04def
__init__(self, first, last, sal):
self.first=first
self.last=last
self.sal=sal
self.email=first + '.' + last + '@company.com'
employee.num_employee+=1def fullname (self):
return '{} {}'.format(self.first, self.last)
def apply_raise (self):
self.sal=int(self.sal *raise_amount)
class developer (employee):
pass
emp_1=developer('maxwell', 'sage', 1000000)
print(emp_1.email)
#OUTPUT - maxwell.sage@company.com
Engant.com 54
Chapter-6:Object Oriented Programming
Encapsulation
Encapsulation basically means binging up of data in a
single class. Python does not have any private keywords,
unlike java. A class shouldn't be directly accessed but be
prefixed in an underscore.
Refer to the code given below. Making use of the setter
method provides indirect access to the private class
method. Here I have defined a class employee and used
a (_maxearn) which is the setter method used here to
store the maximum earning of the employee, and a
setter function setmaxearn( ) which is taking price as
the parameter.
This is a clear example of encapsulation where we are
restricting the access to the private class method and
then use the setter method to grant acess.
Engant.com 55
Chapter-6:Object Oriented Programming
EXAMPLE:-
class employee():
def __init__(self):
self.__maxearn = 1000000
def earn(self):
print("earning is {}".format(self.__maxearn))
def setmaxearn(self,earn):
#setter method used for accesing
private class
self.__maxearn = earn
emp1 = employee()
emp1.earn()
emp1.__maxearn = 10000
emp1.earn()
emp1.setmaxearn(10000)
emp1.earn()
#earning is:1000000,earning
is:1000000,earning is:10000
Engant.com 56
Chapter-6:Object Oriented Programming
Polymorphism
Polymorphism in Computer Science is the ability to present the
same interface for different underlying forms. Polymorphism
means that if class B inherits from class A, it doesn’t have to
inherit everything about class A. It can do some of the things that
class A does differently. It is most commonly used while dealing
with inheritance. Python is implicitly polymorphic, it has the
ability to overload standard operators, so that they have
appropriate behavior based on their context.
Types of
Polymorphism
1
2
Compile-Time
Polymorphism
Run-Time
Polymorphism
Engant.com 57
Chapter-6:Object Oriented Programming
class Animal:def __init__(self,name):
self.name=name
def talk(self):pass
class Dog(Animal):def talk(self):
print('Woof')
class Cat(Animal):def talk(self):
print('Meow!')
c= Cat('kitty')
c.talk()
d=Dog(Animal)
d.talk()
#OUTPUT - Meow!
#OUTPUT - Woof
EXAMPLE:-
Engant.com 58
Chapter-7:Python Programs For Practice
PYTHON PROGRAMS
FOR PRACTICE
FEW PYTHON PROGRAMMES:-
Program for factorial of a number.
Program for the n-th Fibonacci number using
recursion.
Program to swap two elements in a list.
Reverse a number using a loop.
Bubble sort in Python.
Program of Diamond Pattern With Numbers.
Program Maximum & minimum elements in the tuple.
Program to find the sum of all items in a dictionary.
Engant.com 59
Chapter-7:Python Programs For Practice
Program for factorial of a number
# Python 3 program to find
# factorial of given number
def factorial(n):
# single line to find factorial
return 1
if (n==1 or n==0)
else n * factorial(n -1);
# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial(num))
#Factorial of 5 is 120
Engant.com 60
Chapter-7:Python Programs For Practice
Program for n-th fibonacci number
using recursion
# Function for nth Fibonacci number
def Fibonacci(n):
if n<= 0:
print("Incorrect input")
# First Fibonacci number is 0
elif n == 1:
return 0
# Second Fibonacci number is 1
elif n == 2:
return 1
else:
return Fibonacci(n- 1)+Fibonacci(n- 2)
# Print n-th Fibonacci number
print(Fibonacci(10))
# Output is 34
Engant.com 61
Chapter-7:Python Programs For Practice
Program to swap two elements
in a list
# Python3 program to swap elements
# at given positions
# Swap function
def swapPositions(list, pos1, pos2):
list[pos1], list[pos2] = list[pos2],
list[pos1]
return list
# Driver function
List = [23, 65, 19, 90]
pos1, pos2 = 1, 3
print(swapPositions(List, pos1-1, pos2-1))
#Output is [19, 65, 23, 90]
Engant.com 62
Chapter-7:Python Programs For Practice
Program for reverse a number
using loop
# Python Program to Reverse a Number
using While loop
Number = int(input("Please Enter any
Number: "))
Reverse = 0
while (Number > 0):
Reminder = Number %10
Reverse = (Reverse *10) + Reminder
Number = Number //10
print("n Reverse of entered number is =
%d" %Reverse)
#Input from the user is 4569
#output is 9654
#Program for bubble sort in python
def bubblesort(elements):
# Looping from size of array from last index[-1] to
index [0]
for n in range(len(elements)-1, 0, -1):
for i in range(n):
if elements[i] > elements[i + 1]:
# swapping data if the element is less than next
element in the array
elements[i], elements[i + 1] = elements[i + 1],
elements[i]
elements = [39,12,18,85,72,10,2,18]
print("Unsorted list is,")
print( elements)
bubblesort(elements)
print("Sorted Array is, ")
print(elements)
Engant.com 63
Chapter-7:Python Programs For Practice
Bubble sort in python
Output:
Unsorted list is,
[39, 12, 18, 85, 72, 10, 2, 18]
Sorted Array is,
[2, 10, 12, 18, 18, 39, 72, 85
Engant.com 64
Chapter-7:Python Programs For Practice
Program of diamond pattern
with numbers
def pattern(n):
k = 2 * n - 2
x = 0
for i in range(0, n):
x += 1
for j in range(0, k):
print(end=" ")
k = k - 1
for j in range(0, i + 1):
print(x, end=" ")
print(" ")
k = n - 2
x = n + 2
for i in range(n, -1, -1):
x -= 1
for j in range(k, 0, -1):
print(end=" ")
k = k + 1
for j in range(0, i + 1):
print(x, end=" ")
print(" ")
pattern(5)
Output:-
Engant.com 65
Chapter-7:Python Programs For Practice
Program to find maximum
& minimum in the tuple
# Python3 code to demonstrate working of
# Maximum and Minimum K elements in Tuple
# Using slicing + sorted()
# initializing tuple
test_tup = (5, 20, 3, 7, 6, 8)
# printing original tuple
print("The original tuple is : " + str(test_tup))
# initializing K
K = 2
# Maximum and Minimum K elements in Tuple
# Using slicing + sorted()
test_tup = list(test_tup)
temp = sorted(test_tup)
res = tuple(temp[:K] + temp[-K:])
# printing result
print("The extracted values : " + str(res))
#Output :
The original tuple is : (5, 20, 3, 7, 6, 8)
The extracted values : (3, 5, 8, 20)
Engant.com 66
Chapter-7:Python Programs For Practice
Program to find the sum of
all items in a dictionary
# Python3 Program to find the sum of
# all items in a Dictionary
# Function to print sum
def returnSum(myDict):
list = [ ]
for i in myDict:
list.append(myDict[i])
final = sum(list)
return final
# Driver Function
dict = {'a': 100, 'b':200, 'c':300}
print("Sum :", returnSum(dict))
#Output
sum is 600.
Chapter-8: Faq's & career guidance
Engant.com 67
FREQUENTLY
ASKED
INTERVIEW
QUESTIONS
Chapter-8:
Today Python has evolved as the most preferred language and is considered to
be the “Next Big Thing” and a “Must” for Professionals. This chapter covers the
questions that will help you in your Python Interviews and open up various
Python career opportunities available for a Python programmer.
1. What type of language is Python?
2. What are the key features of Python?
3. What is the difference between lists and tuples?
4. What are Python modules?
5. What are various built-in data types in Python?
6. What is the difference between arrays and lists?
7. What is __init__?
8. What is a Lambda function?
9. What are the generators in Python?
10. What are docstrings in Python?
11. What is type conversion in Python?
12. How is memory managed in Python?
13. What is a dictionary in Python?
14. What is: *args, **kwargs & why is it used?
15. What is a negative index?
16. What are Python packages?
17. Does Python have OOps concepts?
18. Difference between deep and shallow copy?
19. How is Multithreading achieved in Python?
20. What are Python libraries?
21. What type of language is Python?
22. What is monkey patching in Python?
23. Does python support multiple Inheritance?
24. What is Polymorphism? What are its types?
25. How do you do data Abstraction in Python?
26. Can you create an empty class in Python?
27. WAP in Python to print a Star Pyramid.
28. Explain what Flask is and its benefits?
29. Differentiate between Django, Pyramid, and Flask
30. How you can set up the Database in Django.
Chapter-9: career Guidance
CAREER
GUIDANCE
WHO IS A PYTHON DEVELOPER?
There is no textbook definition for a
Python Developer, there are certain
domains and job roles a Python
Developer can take according
to the skill-set they have.
A Software Developer/Engineer must be well-versed with core
Python, web frameworks, and Object-relational mappers. They
should have an understanding of multi-process architecture and
RESTful APIs to integrate applications with other components.
Front-end development skills and database knowledge are a few
nice-to-have skills for a software developer. Writing Python scripts
and system administration is also an add-on when you are aiming
to become a Software Developer.
SOFTWARE DEVELOPER
68
Engant.com
A Data Scientist should have a thorough knowledge
of Data Analysis and Data Interpretation, Data
Manipulation, Mathematics andStatistics in order to
help in the decision-making process. They also have
to be experts in Machine Learning and with all the
Machine Learning algorithms like Regression
Analysis, Naive-Bayes, etc. A Data Scientist
must know libraries like Tensorflow, Scikit-learn, etc.,
thoroughly. A Data scientist is going to fulfill roles
that involve all-round development.
Chapter-9: Career Guidance
Data Scientist
Engant.com 69
A Python Web Developer is required to
write server-side web logic. They should
be familiar with web frameworks and
HTML and CSS are the foundation
stones for Web Development. Good
Database knowledge and writing Python
scripts is a nice-to-have skills. Libraries like
Tkinter for GUI-based Web Applications is
a must. Master all these skills and you will
become a Python Web Developer
Chapter-9: Career Guidance
Python Developer
Engant.com 70
A Data Analyst is required to carry out
Data Interpretation and Analysis. They
should be well versed with Mathematics
and Statistics. Python libraries like
Numpy, Pandas, Matplotlib, Seaborn etc.,
are used for Data Visualization and
Manipulation and hence, learning Python
can be boon here as well.
Chapter-9: Career Guidance
Data Analyst
Engant.com 71
Machine Learning Engineer must
understand the Deep Learning
concepts along with Neural-Network
architecture and Machine Learning
algorithms on top of Mathematics and
Statistics. A Machine Learning
Engineer must be proficient enough in
Algorithms like Gradient Descent,
Regression Analysis and building
Prediction Models.
Chapter-9: Career Guidance
Machine Learning
Engant.com 72
Engant.com 73
Chapter-9: References
Python Certification Program
Paid Courses:
Python for Everybody
Specialization -Coursera
2022 Complete Python
Bootcamp From Zero to Hero in
Python -Udemy
Google IT Automation with
Python Professional Certificate
-Google
Python for Data Science, AI &
Development -IBM
Engant.com 74
Chapter-9: References
Python Certification Program
Free Courses:
Python Courses- Udemy
Google’s Python Course -
Google
Free Python Courses for
Beginners -Freecodecamp
Programming with Python
3.X - Simplilearn
Python for Beginners -
Simplilearn
I HOPE YOU ENJOYED!
Engant 2022
Mohammed Aman Nawaz

Weitere ähnliche Inhalte

Ähnlich wie Introduction to python3.pdf

a9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptx
a9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptxa9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptx
a9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptxcigogag569
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfVaibhavKumarSinghkal
 
PYTHO programming NOTES with category.pdf
PYTHO programming NOTES with category.pdfPYTHO programming NOTES with category.pdf
PYTHO programming NOTES with category.pdfdeivasigamani9
 
PYTHON PROGRAMMING NOTES.pdf
PYTHON PROGRAMMING NOTES.pdfPYTHON PROGRAMMING NOTES.pdf
PYTHON PROGRAMMING NOTES.pdfRajathShetty34
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonRanjith kumar
 
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON Nandakumar P
 
Python Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PunePython Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PuneEthan's Tech
 
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfCSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfAbdulmalikAhmadLawan2
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptxKaviya452563
 

Ähnlich wie Introduction to python3.pdf (20)

a9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptx
a9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptxa9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptx
a9855c3532e13484ee6a39ba30218896d7c0d863-1676987272842.pptx
 
Chapter - 1.pptx
Chapter - 1.pptxChapter - 1.pptx
Chapter - 1.pptx
 
1.Basic_Syntax
1.Basic_Syntax1.Basic_Syntax
1.Basic_Syntax
 
Python basic syntax
Python basic syntaxPython basic syntax
Python basic syntax
 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdf
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdf
 
PYTHO programming NOTES with category.pdf
PYTHO programming NOTES with category.pdfPYTHO programming NOTES with category.pdf
PYTHO programming NOTES with category.pdf
 
PYTHON PROGRAMMING NOTES.pdf
PYTHON PROGRAMMING NOTES.pdfPYTHON PROGRAMMING NOTES.pdf
PYTHON PROGRAMMING NOTES.pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
 
INTERNSHIP REPORT.docx
 INTERNSHIP REPORT.docx INTERNSHIP REPORT.docx
INTERNSHIP REPORT.docx
 
PHYTON-REPORT.pdf
PHYTON-REPORT.pdfPHYTON-REPORT.pdf
PHYTON-REPORT.pdf
 
Python Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech PunePython Training in Pune - Ethans Tech Pune
Python Training in Pune - Ethans Tech Pune
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfCSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
 
python unit2.pptx
python unit2.pptxpython unit2.pptx
python unit2.pptx
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptx
 

Kürzlich hochgeladen

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Kürzlich hochgeladen (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

Introduction to python3.pdf

  • 1. INTRODUCTION TO PYTHON3 IN 2022 MOHAMMED AMAN NAWAZ BY ENGANT.COM
  • 2. PYTHON 3 INTRODUCTION Introduction To Python 4 Python Installation 13 Python Fundamentals 21 Data Types in Python 30 Flow of Control in Python 39 Python OOPS concepts 47 Python Practice Programs 58 Top 30 Interview Questions 67 Career Guidance 68 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. References 73
  • 3. Engant.com A few words of acknowledgment... First and foremost, To my highest source of inspiration, the Supreme Speaker Those words I only channel... My MOM & DAD! Then to the true support throughout my career, both friends and family... you've all been amazing! And last but not least, to YOU, my dear reader... and my real reason! Thank you all... Namaste! Copyright © Engant ALL RIGHTS RESERVED This eBook or any portion thereof may not be reproduced or used in any manner whatsoever without the express written permission of the copyright owner and publisher except for the use of brief quotations in a book review, online, or in print. First Publication: 2022 Version: 1.00 support@engant.com BEFORE WE START!
  • 4. What is Python? TOPICS COVERED:- What is Python? Features Of Python Why choose Python? What is Python3? Chapter-1: What is Python Engant.com 4
  • 5. Chapter-1: What is Python Engant.com 5 What is Python? Python is a high-level, interpreted scripting language developed in the late 1980s by Guido van Rossum at the National Research Institute for Mathematics and Computer Science in the Netherlands. The initial version was published at the alt. sources newsgroup in 1991, and version 1.0 was released in 1994.
  • 6. Chapter-1: What is Python Engant.com 6 Features Of Python
  • 7. Chapter-1: What is Python Engant.com Why Choose Python? Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages 7
  • 8. Chapter-1: What is Python Engant.com 8 Python is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Web Development Domain. I will list down some of the key advantages of learning Python:
  • 9. Chapter-1: What is Python Engant.com 9 Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP. Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter directly to write your programs
  • 10. Chapter-1: What is Python Engant.com Python is Object-Oriented − Python supports the Object- Oriented style or technique of programming that encapsulates code within objects. Python is a Beginner's Language − Python is a great language for beginner-level programmers and supports the development of a wide range of applications from simple text processing to www browsers to games 10
  • 11. Chapter-1: What is Python Engant.com 11 What is Python3? Python 3.0 was released in 2008. Although this version is supposed to be backward incompatibles, later on many of its important features have been backported to be compatible with version 2.7.This tutorial gives enough understanding on Python 3 version programming language.
  • 12. Chapter-1: What is Python Engant.com 12 Applications Of Python
  • 13. Chapter-2: Python3 Installation & Setup Engant.com Python3 Installation & Setup TOPICS COVERED:- DOWNLOADING PYTHON INSTALLING PYTHON ON WINDOWS macOS LINUX BEST PYTHON IDE's 1. 2. 3. 13
  • 14. Engant.com 14 Chapter-2: Python3 Installation & Setup Downloading Python 1. Go to www.python.org/downloads/ 2. Download Python as per your system requirement. Python3 Installation
  • 15. Engant.com 15 Chapter-2: Python3 Installation & Setup Installing Python On Windows 1. Click on Python Releases for Windows, select the link for the latest Python 3 Release – Python 3.x.x 2. Scroll to the bottom and select either Windows x86-64 executable installer for 64-bit or Windows x86 executable installer for 32-bit
  • 16. 1. Click on Python Releases for macOS, select the link for the latest Python 3 Release – Python 3.x.x 2. Scroll to the bottom and select either Windows x86-64 executable installer for 64-bit or Windows x86 executable installer for 32-bit Engant.com Chapter-2: Python3 Installation & Setup Installing Python On macOS 16
  • 17. 1. Open the Ubuntu Software Center folder 2. Select Developer Tools from the All Software drop-down list box 3. Double-click the Python 3.3.4 entry 4. Click Install 5. Close the Ubuntu Software Center folder Engant.com 17 Chapter-2: Python3 Installation & Setup Installing Python On Linux
  • 18. Engant.com 18 Chapter-2: Python3 Installation & Setup Best Python IDE's IDE stands for Integrated Development Environment which is a Graphical User Interface where programmers write their code to produce the final products. An IDE basically unifies all essential tools required for software development and testing. In order to make the best use of this e-book, install an IDE now and start implementing the Python concepts as you learn.
  • 19. Engant.com 19 Chapter-2: Python3 Installation & Setup TOP PYTHON IDE's Pycharm Jupyter Notebook Atom
  • 20. Engant.com 20 Chapter-2: Python3 Installation & Setup Level of expertise of the programmer The type of industry or sector where Python is being used Ability to buy commercial versions or Kind of software being developed Integration with other languages Always keep the following points in mind while choosing the best IDE for Python: stick to the free ones Points To Remember while choosing IDE's
  • 21. Chapter-3: Python Fundamentals Engant.com 21 PYTHON FUNDAMENTALS TOPICS COVERED:- Keywords Identifiers Variables Comments Operators Function Function parameter
  • 22. Keywords are nothing but special names that are already present in python. We can use these keywords for specific functionality while writing a python program. #retrieving all keywords import keyword keyword.kwlist # keyword.iskeyword(' try ') #this will return true, if the mentioned name is a keyword Chapter-3: Python Fundamentals Engant.com 22 Keywords
  • 23. Identifiers are user-defined names that we use to represent variables, classes, functions, modules, etc. name = ' engant ' my_identifier = name #this will return the value of the identifier provided by the user Chapter-3: Python Fundamentals Engant.com 23 Identifiers
  • 24. Variables are like a memory location where you can store a value. This value, you may or may not change in the future. x = 10 y = 20 name = ' engant ' #To declare a Python variable you only have to assign a value to it Chapter-3: Python Fundamentals Engant.com 24 Variables
  • 25. Chapter-3: Python Fundamentals Engant.com 25 Single-line or Multi-line Comments in programming are the program coherent statements, that describe what a block of code means. They are very useful when you are writing large codes. Comments in Python start with a # character. Alternatively, at times, commenting is done using docstrings (strings enclosed within triple quotes). Python Comments can be of two types: #Comments in Python start like this print("Comments in Python start with a #") Comments
  • 27. Operators in Python are used for operations between two values or variables. The output varies according to the type of operator used in the operation. We can call operators as special symbols or constructs to manipulate the values of the operands. Consider the expression 2 + 3 = 5, here 2 and 3 are operands and + is called operator Chapter-3: Python Fundamentals Engant.com 27
  • 28. A function in Python is a block of code that will execute whenever it is called. We can pass parameters in the functions as well. To understand the concept of functions, let's take an example. Suppose you want to calculate the factorial of a number. You can do this by simply executing the logic to calculate a factorial. But what if you have to do it ten times a day, writing the same logic, again and again, is going to be a long task. Instead, what you can do is, write the logic in a function. Call that function every time you need to calculate the factorial. This will reduce the complexity of your code and save your time as well. Chapter-3: Python Fundamentals Engant.com 28 Functions #declaring a function def function_name(): #expression print('abc')
  • 29. Chapter-3: Python Fundamentals Engant.com 29 We can pass values in a function using the parameters. We can use also give the default values for a parameter in a function as well. Function Parameters #calling a function #default parameter def my_func(): my_func( ) print('function created') #this is a function call #userdefined parameter my_func() my_func('python') # def my_func (name = 'engant'): print(name)
  • 30. Chapter-4: Data Types Engant.com 30 DATA TYPES TOPICS COVERED:- Numeric String List Tuple Set Dictionary
  • 31. Chapter-4: Data Types Engant.com DATA TYPES IN PYTHON A Variable in python is created as soon as a value is assigned to it. It does not need any additional commands to declare a variable in python. There are certain rules and regulations we have to follow while writing a variable, lets's take a look at the variable definition and declaration to understand how we declare a variable in python Variables and data types in python as the name suggests are the values that vary. In a programming language, a variable is a memory location where you store a value. The value that you have stored may change in the future according to the specifications Name= ' engant ' A=10; B=20; Name= engant A=10 B=20 Variable Memory 31
  • 32. Chapter-4: Data Types Engant.com 32 According to the properties they possess, there are mainly six data types in python. Although there is one more data type range which is often used while working with loops in python. DATA TYPES IN PYTHON
  • 33. Numerical data type holds numerical value. In numerical data, there are 4 subtypes as well. Following are the sub-types of numerical data type: a. Integers - Integers are used to represent whole number values b. Float - Float data type is used to represent decimal point values c. Complex Numbers - Complex numbers are used to represent imaginary values d. Boolean - Boolean is used for categorical output, since the output of boolean is either true or false Chapter-4: Data Types Engant.com 33 Numeric 1.
  • 34. String in python are used to represent Unicode characters values. Python does not have a character data type, a single character is considered as a string. We declare the string values within the single quotes or double quotes. Indexes & Square brackets are used to access the values. Strings are immutable in nature. Chapter-4: Data Types Engant.com 2.String E N A G N T 0 1 2 3 4 5 4 -1 -2 -3 -4 -5 -6 34
  • 35. name = 'engant' name[2] #this will give you the output as 'n' name = 'engant' name.upper() #this will make the letters to uppercase name.lower() #this will make the letters to lowercase name.replace('e') = 'E' #this will replace the letter 'e' with 'E' name[1: 4] #this will return the strings starting at index 1 until the index 4 Chapter-4: Data Types Engant.com 35
  • 36. List is one of the four collection data types that we have in python. When we are choosing a collection type, it is important to understand the functionality and limitations of the collection. Tuple, set and dictionary are the other collection data type in Python. A list is ordered and changeable, unlike strings. We can add duplicate values as well. To declare a list, we use the square brackets. Chapter-4: Data Types Engant.com 36 3. List mylist = [10,20,30,40,20,30, 'eng'] mylist.append('engant') mylist[2:6] #this will add the value at the #this will get the values end. from index 2 to 6. . [6] = 'python' mylist.insert(5, 'data science') #this will replace the #this will add the value at value at the index the index 5. 6.
  • 37. Chapter-4:Data Types Engant.com 37 A tuple is an ordered data structure whose values can be accessed using the index values. It can have duplicate values. To declare a tuple, we use the round brackets. A tuple is a read-only data structure and you cannot modify the size and value of the items of a tuple. 4. Tuple #declaring a tuple mytuple = (10,10, 20, 30, 40, 50) #counting total number of elements mytuple.count(10) #to find an item index mytuple.index(50) #output will be 5
  • 38. Chapter-4:Data Types Engant.com 38 A set is a collection that is unordered & doesn't have any index. To declare sets in Python, we use curly brackets. A set does not have any duplicate values. Even though it will not show any errors while declaring the set, the output will only have distinct values. 5.Set myset = { 10, 20 , 30 , 40, 50, 50} #to add a value in a set. myset.add('engant') #to add multiple values in a list myset.update([ 10, 20, 30, 40, 50]) #to remove an item from a set myset.remove('engant') 6.Dictionary A dictionary is just like any other collection array in Python. But they have key-value pairs. A dictionary is unordered and changeable. We use the keys to access the items from a dictionary. To declare a dictionary, we use curly brackets. mydictionary = { 'python' : 'data science' , 'machine learning' : 'tensorflow' , 'artificial intelligence' : 'keras'} mydictionary['machine learning'] #this will give the output as 'tensorflow' mydictionary.get('python') #this serves the same purpose to access the value
  • 39. Chapter-5: Flow Of Control Engant.com 39 FLOW OF CONTROL TOPICS COVERED:- Conditional Statements If statement Else statement Elif statement Iterative Statements 1. 2. 3. 1. For Loop 2. While Loop
  • 40. Chapter-5: Flow Of Control Engant.com 40 FLOW OF CONTROL Code runs sequentially in any language, but what if you want to break that flow such that you are able to add logic and repeat certain statements such that your code reduces and are able to obtain a solution with lesser and smarter code. After all, that is what coding is. Finding logic and solutions to problems and can be done using Conditional and Iterative statements.
  • 41. Chapter-5: Flow Of Control Engant.com 41 Conditional Statements Conditional statements are executed only if a certain condition is met, else it is skipped ahead to where the condition is satisfied. There are various types of conditional statements supported in Python. I F An if statement is used to test an expression and execute certain statements accordingly. A program can have many if statements.
  • 42. Chapter-5: Flow Of Control Engant.com 42 An else statement is used with an if statement. Else contains the block of a code that executes if the conditional expression in the 'if statement' is FALSE E L S E E L I F The elif statement allows a number of expression checks for TRUE and execute a block of code as soon as one of the conditions returns TRUE
  • 43. Chapter-5: Flow Of Control Engant.com 43 if condition :statement elif condition :statement else :statement This means that if a condition is met, do something. Else go through the remaining elif conditions and finally if no condition is met, execute the else block. You can even have nested if-else statements inside the if-else blocks. a = 15 b = 20 if a == b: print ( 'They are equal' ) elif a > b: print ( 'a is larger' ) else : print ( 'b is larger' ) Example:- Output:- b is larger
  • 44. Chapter-5: Flow Of Control Engant.com 44 Iterative Statements
  • 45. Chapter-5: Flow Of Control Engant.com 45 Loops in Python allow us to execute a group of statements several times. Loops can be divided into 2 kinds: a. Finite: This kind of loop works until a certain condition is met b. Infinite: This kind of loop works infinitely and does not stop ever Loops in Python or any other languages have to test the condition and they can be done either before the statements or after the statements. They are called: a. Pre-Test Loops: Where the conditions are tested first and statements are executed subsequently. b. Post-Test Loops: Where the statement is executed at least once and later the condition is checked
  • 46. Chapter-5: Flow Of Control Engant.com 46 FOR FOR This loop is used to perform a certain set of statements for a given condition and continue until the condition has failed WHILE WHILE This loop in Python is used to iterate over a block of code or statements as long as the test expression is true. #syntax for variable in range: statements #example fruits_Basket= ['apple', 'orange', 'pineapple', 'banana'] for fruit in fruits_Basket: print(fruit, end=',') #Output is apple, orange, pineapple, banana #syntax while (test expression): statements #example second = 5 while second >= 0: print(second, end='->') second-=1 print('Blastoff!') #Output is 5->4->3->2->1->Blastoff!
  • 47. Chapter-6:Object Oriented Programming Engant.com 4 OBJECT ORIENTED PROGRAMMING (OOP) IN PYTHON TOPICS COVERED:- Classes & Objects Abstraction Inheritance Encapsulation Polymorphism 7
  • 48. Chapter-6:Object Oriented Programming Engant.com 48 Object-Oriented Programming (OOP) is a way of computers using the idea of objects to represent data and methods. It is also an approach used for creating neat and reusable code instead of a redundant one. The program is divided into self- contained objects or several mini-programs. Every individual object represents a different part of the application having its own logic and data to communicate within itself. Classes & Objects class is a collection or you can say it is a blueprint of objects defining the common attributes and behavior. It logically groups the data in such a way that code reusability becomes easy. Class is defined under a " Class " Keyword. Using a Class, you can add consistency to your programs so that they can be used in an efficient way. The attributes of a class are listed below:
  • 49. #syntax class EduClass(): Objects are an instance of a class. It is an entity that has a state and behavior. In a nutshell, it is an instance of a class that can access the data. #syntax class EduClass: def func (self): print('Hello') # create a new EduClass ob = EduClass() ob.func() Chapter-6:Object Oriented Programming Engant.com 49 a.Class variable is a variable that is shared by all the different objects/instances of a class. b. Instance variables are variables that are unique to each instance. It is defined as a method and belongs only to the current instance of a class. c. Methods are also called functions that are defined in a class and describe the behavior of an object.
  • 50. Chapter-6:Object Oriented Programming Engant.com 50 Abstraction Abstraction is used to simplify complex reality by modeling classes appropriate to the problem. Here, we have an abstract class that cannot be instantiated. This means you cannot create objects or instances for these classes. It can only be used for inheriting certain functionalities which you call a base class. So you can inherit functionalities but at the same time, you cannot create an instance of this particular class. Let’s understand the concept of abstract class with an example.
  • 51. from abc import ABC, abstractmethod class Employee (ABC): @abstractmethod def calculate_salary (self,sal): pass class Developer (Employee): def calculate_salary(self,sal): finalsalary= sal*1.10 return finalsalary emp_1 = Developer() print(emp_1.calculate_salary(10000)) #OUTPUT - 11000.0 Chapter-6:Object Oriented Programming Engant.com 51 EXAMPLE:-
  • 52. Inheritance allows us to inherit attributes and methods from the base/parent class. This is useful as we can create sub-classes and get all of the functionality from our parent class. Then we can overwrite and add new functionalities without affecting the parent class. A class that inherits the properties is known as Child Class whereas a class whose properties are inherited is known as Parent class. Chapter-6:Object Oriented Programming Engant.com 52 Inheritance TYPES OF INHERITANCE Single Inheritance Multilevel Inheritance Hierarchical Inheritance Multiple Inheritance
  • 53. Chapter-6:Object Oriented Programming Engant.com 53 EXAMPLE:- class employee: num_employee=0 raise_amount=1.04def __init__(self, first, last, sal): self.first=first self.last=last self.sal=sal self.email=first + '.' + last + '@company.com' employee.num_employee+=1def fullname (self): return '{} {}'.format(self.first, self.last) def apply_raise (self): self.sal=int(self.sal *raise_amount) class developer (employee): pass emp_1=developer('maxwell', 'sage', 1000000) print(emp_1.email) #OUTPUT - maxwell.sage@company.com
  • 54. Engant.com 54 Chapter-6:Object Oriented Programming Encapsulation Encapsulation basically means binging up of data in a single class. Python does not have any private keywords, unlike java. A class shouldn't be directly accessed but be prefixed in an underscore. Refer to the code given below. Making use of the setter method provides indirect access to the private class method. Here I have defined a class employee and used a (_maxearn) which is the setter method used here to store the maximum earning of the employee, and a setter function setmaxearn( ) which is taking price as the parameter. This is a clear example of encapsulation where we are restricting the access to the private class method and then use the setter method to grant acess.
  • 55. Engant.com 55 Chapter-6:Object Oriented Programming EXAMPLE:- class employee(): def __init__(self): self.__maxearn = 1000000 def earn(self): print("earning is {}".format(self.__maxearn)) def setmaxearn(self,earn): #setter method used for accesing private class self.__maxearn = earn emp1 = employee() emp1.earn() emp1.__maxearn = 10000 emp1.earn() emp1.setmaxearn(10000) emp1.earn() #earning is:1000000,earning is:1000000,earning is:10000
  • 56. Engant.com 56 Chapter-6:Object Oriented Programming Polymorphism Polymorphism in Computer Science is the ability to present the same interface for different underlying forms. Polymorphism means that if class B inherits from class A, it doesn’t have to inherit everything about class A. It can do some of the things that class A does differently. It is most commonly used while dealing with inheritance. Python is implicitly polymorphic, it has the ability to overload standard operators, so that they have appropriate behavior based on their context. Types of Polymorphism 1 2 Compile-Time Polymorphism Run-Time Polymorphism
  • 57. Engant.com 57 Chapter-6:Object Oriented Programming class Animal:def __init__(self,name): self.name=name def talk(self):pass class Dog(Animal):def talk(self): print('Woof') class Cat(Animal):def talk(self): print('Meow!') c= Cat('kitty') c.talk() d=Dog(Animal) d.talk() #OUTPUT - Meow! #OUTPUT - Woof EXAMPLE:-
  • 58. Engant.com 58 Chapter-7:Python Programs For Practice PYTHON PROGRAMS FOR PRACTICE FEW PYTHON PROGRAMMES:- Program for factorial of a number. Program for the n-th Fibonacci number using recursion. Program to swap two elements in a list. Reverse a number using a loop. Bubble sort in Python. Program of Diamond Pattern With Numbers. Program Maximum & minimum elements in the tuple. Program to find the sum of all items in a dictionary.
  • 59. Engant.com 59 Chapter-7:Python Programs For Practice Program for factorial of a number # Python 3 program to find # factorial of given number def factorial(n): # single line to find factorial return 1 if (n==1 or n==0) else n * factorial(n -1); # Driver Code num = 5; print("Factorial of",num,"is", factorial(num)) #Factorial of 5 is 120
  • 60. Engant.com 60 Chapter-7:Python Programs For Practice Program for n-th fibonacci number using recursion # Function for nth Fibonacci number def Fibonacci(n): if n<= 0: print("Incorrect input") # First Fibonacci number is 0 elif n == 1: return 0 # Second Fibonacci number is 1 elif n == 2: return 1 else: return Fibonacci(n- 1)+Fibonacci(n- 2) # Print n-th Fibonacci number print(Fibonacci(10)) # Output is 34
  • 61. Engant.com 61 Chapter-7:Python Programs For Practice Program to swap two elements in a list # Python3 program to swap elements # at given positions # Swap function def swapPositions(list, pos1, pos2): list[pos1], list[pos2] = list[pos2], list[pos1] return list # Driver function List = [23, 65, 19, 90] pos1, pos2 = 1, 3 print(swapPositions(List, pos1-1, pos2-1)) #Output is [19, 65, 23, 90]
  • 62. Engant.com 62 Chapter-7:Python Programs For Practice Program for reverse a number using loop # Python Program to Reverse a Number using While loop Number = int(input("Please Enter any Number: ")) Reverse = 0 while (Number > 0): Reminder = Number %10 Reverse = (Reverse *10) + Reminder Number = Number //10 print("n Reverse of entered number is = %d" %Reverse) #Input from the user is 4569 #output is 9654
  • 63. #Program for bubble sort in python def bubblesort(elements): # Looping from size of array from last index[-1] to index [0] for n in range(len(elements)-1, 0, -1): for i in range(n): if elements[i] > elements[i + 1]: # swapping data if the element is less than next element in the array elements[i], elements[i + 1] = elements[i + 1], elements[i] elements = [39,12,18,85,72,10,2,18] print("Unsorted list is,") print( elements) bubblesort(elements) print("Sorted Array is, ") print(elements) Engant.com 63 Chapter-7:Python Programs For Practice Bubble sort in python Output: Unsorted list is, [39, 12, 18, 85, 72, 10, 2, 18] Sorted Array is, [2, 10, 12, 18, 18, 39, 72, 85
  • 64. Engant.com 64 Chapter-7:Python Programs For Practice Program of diamond pattern with numbers def pattern(n): k = 2 * n - 2 x = 0 for i in range(0, n): x += 1 for j in range(0, k): print(end=" ") k = k - 1 for j in range(0, i + 1): print(x, end=" ") print(" ") k = n - 2 x = n + 2 for i in range(n, -1, -1): x -= 1 for j in range(k, 0, -1): print(end=" ") k = k + 1 for j in range(0, i + 1): print(x, end=" ") print(" ") pattern(5) Output:-
  • 65. Engant.com 65 Chapter-7:Python Programs For Practice Program to find maximum & minimum in the tuple # Python3 code to demonstrate working of # Maximum and Minimum K elements in Tuple # Using slicing + sorted() # initializing tuple test_tup = (5, 20, 3, 7, 6, 8) # printing original tuple print("The original tuple is : " + str(test_tup)) # initializing K K = 2 # Maximum and Minimum K elements in Tuple # Using slicing + sorted() test_tup = list(test_tup) temp = sorted(test_tup) res = tuple(temp[:K] + temp[-K:]) # printing result print("The extracted values : " + str(res)) #Output : The original tuple is : (5, 20, 3, 7, 6, 8) The extracted values : (3, 5, 8, 20)
  • 66. Engant.com 66 Chapter-7:Python Programs For Practice Program to find the sum of all items in a dictionary # Python3 Program to find the sum of # all items in a Dictionary # Function to print sum def returnSum(myDict): list = [ ] for i in myDict: list.append(myDict[i]) final = sum(list) return final # Driver Function dict = {'a': 100, 'b':200, 'c':300} print("Sum :", returnSum(dict)) #Output sum is 600.
  • 67. Chapter-8: Faq's & career guidance Engant.com 67 FREQUENTLY ASKED INTERVIEW QUESTIONS Chapter-8: Today Python has evolved as the most preferred language and is considered to be the “Next Big Thing” and a “Must” for Professionals. This chapter covers the questions that will help you in your Python Interviews and open up various Python career opportunities available for a Python programmer. 1. What type of language is Python? 2. What are the key features of Python? 3. What is the difference between lists and tuples? 4. What are Python modules? 5. What are various built-in data types in Python? 6. What is the difference between arrays and lists? 7. What is __init__? 8. What is a Lambda function? 9. What are the generators in Python? 10. What are docstrings in Python? 11. What is type conversion in Python? 12. How is memory managed in Python? 13. What is a dictionary in Python? 14. What is: *args, **kwargs & why is it used? 15. What is a negative index? 16. What are Python packages? 17. Does Python have OOps concepts? 18. Difference between deep and shallow copy? 19. How is Multithreading achieved in Python? 20. What are Python libraries? 21. What type of language is Python? 22. What is monkey patching in Python? 23. Does python support multiple Inheritance? 24. What is Polymorphism? What are its types? 25. How do you do data Abstraction in Python? 26. Can you create an empty class in Python? 27. WAP in Python to print a Star Pyramid. 28. Explain what Flask is and its benefits? 29. Differentiate between Django, Pyramid, and Flask 30. How you can set up the Database in Django.
  • 68. Chapter-9: career Guidance CAREER GUIDANCE WHO IS A PYTHON DEVELOPER? There is no textbook definition for a Python Developer, there are certain domains and job roles a Python Developer can take according to the skill-set they have. A Software Developer/Engineer must be well-versed with core Python, web frameworks, and Object-relational mappers. They should have an understanding of multi-process architecture and RESTful APIs to integrate applications with other components. Front-end development skills and database knowledge are a few nice-to-have skills for a software developer. Writing Python scripts and system administration is also an add-on when you are aiming to become a Software Developer. SOFTWARE DEVELOPER 68 Engant.com
  • 69. A Data Scientist should have a thorough knowledge of Data Analysis and Data Interpretation, Data Manipulation, Mathematics andStatistics in order to help in the decision-making process. They also have to be experts in Machine Learning and with all the Machine Learning algorithms like Regression Analysis, Naive-Bayes, etc. A Data Scientist must know libraries like Tensorflow, Scikit-learn, etc., thoroughly. A Data scientist is going to fulfill roles that involve all-round development. Chapter-9: Career Guidance Data Scientist Engant.com 69
  • 70. A Python Web Developer is required to write server-side web logic. They should be familiar with web frameworks and HTML and CSS are the foundation stones for Web Development. Good Database knowledge and writing Python scripts is a nice-to-have skills. Libraries like Tkinter for GUI-based Web Applications is a must. Master all these skills and you will become a Python Web Developer Chapter-9: Career Guidance Python Developer Engant.com 70
  • 71. A Data Analyst is required to carry out Data Interpretation and Analysis. They should be well versed with Mathematics and Statistics. Python libraries like Numpy, Pandas, Matplotlib, Seaborn etc., are used for Data Visualization and Manipulation and hence, learning Python can be boon here as well. Chapter-9: Career Guidance Data Analyst Engant.com 71
  • 72. Machine Learning Engineer must understand the Deep Learning concepts along with Neural-Network architecture and Machine Learning algorithms on top of Mathematics and Statistics. A Machine Learning Engineer must be proficient enough in Algorithms like Gradient Descent, Regression Analysis and building Prediction Models. Chapter-9: Career Guidance Machine Learning Engant.com 72
  • 73. Engant.com 73 Chapter-9: References Python Certification Program Paid Courses: Python for Everybody Specialization -Coursera 2022 Complete Python Bootcamp From Zero to Hero in Python -Udemy Google IT Automation with Python Professional Certificate -Google Python for Data Science, AI & Development -IBM
  • 74. Engant.com 74 Chapter-9: References Python Certification Program Free Courses: Python Courses- Udemy Google’s Python Course - Google Free Python Courses for Beginners -Freecodecamp Programming with Python 3.X - Simplilearn Python for Beginners - Simplilearn
  • 75. I HOPE YOU ENJOYED! Engant 2022 Mohammed Aman Nawaz