Edureka Python Ebook
Edureka Python Ebook
TABLE OF CONTENTS
1. INTRODUCTION TO PYTHON 3
2. PYTHON INSTALLATION 5
3. PYTHON FUNDAMENTALS 6
Keywords & Identi ers
Variables
Comments
Operators
Functions
Iterative Statements
Conditional Statements
TABLE OF CONTENTS
9. CAREER GUIDANCE 18
How to become a Python Developer?
Edureka's Structured Training Programs
10. REFERENCES 19
Chapter 1
INTRODUCTION TO
PYTHON
PROGRAMMING
Programming languages have been around for ages, and every decade sees the
launch of a new language sweeping developers off their feet. Python is considered
as one of the most popular and in-demand programming languages. A recent
Stack Overflow survey showed that Python has taken over languages such as
Java, C, C++ and has made its way to the top. This makes Python Programming
one of the most sought-after programming languages across the globe.
Applications
GUI Based Applications Game Development Prototyping Python
Chapter 2
PYTHON INSTALLATION
2.1 Downloading Python
1. Go to www.python.org/downloads/
2. Download Python as per your system requirement
INSTALLING 1. Click on Python Releases for Windows, select the link for the latest Python
3 Release – Python 3.x.x
PYTHON ON 2. Scroll to the bottom and select either Windows x86-64 executable
WINDOWS installer for 64-bit or Windows x86 executable installer for 32-bit
Chapter 3
PYTHON FUNDAMENTALS
3.1 Keywords and Identifiers
Keywords are nothing but special names Identifiers are user-defined names that
that are already present in python. We can we use to represent variables, classes,
use these keywords for specific functionality functions, modules, etc.
while writing a python program.
3.4 Operators
Operators in Python are
used for operations Type Operators
between two values or Arithmetic +, -, *, /, %, **, //
variables. The output
varies according to the Assignment =, +=, -=, *=, %=, **=, //=, |=, ^=, &=
type of operator used in
the operation. We can Comparison ==, !=, >, <, <=,>=
call operators as special Logical and, or, not
symbols or constructs to
manipulate the values of Membership in, not in
the operands. Consider
the expression 2 + 3 = 5, Identity is, is not
here 2 and 3 are Bitwise &, |, ^, ~, <<,>>
operands and + is called
operator.
3.5 Functions
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 in 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.
#calling a function
#declaring a function
def my_func():
def function_name():
print('function created')
#expression #this is a function call
print('abc') my_func()
#
def my_func(name = 'edureka'):
Function Parameters print(name)
Chapter 4
1 2 3 4 5 6
Numeric String List Tuple Set Dictionary
4.1 Numeric
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
4.2 String
Strings in Python are used to represent Unicode name = 'edureka'
character values. Python does not have a character name[2]
#this will give you the output as 'u'
data type, a single character is also considered as a
string. We declare the string values within single name = 'edureka'
name.upper()
quotes or double-quotes. Indexes and square #this will make the letters to
brackets are used to access the values. Strings are uppercase
name.lower()
immutable in nature. #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 IN: 9606058406
sales@edureka.co
US: 18338555775
9 WWW.EDUREKA.CO/PYTHON
4.3 List
List is one of the four collection data type that
mylist = [10,20,30,40,20,30, 'edu']
we have in python. When we are choosing a mylist[2:6]
collection type, it is important to understand #this will get the values from index 2 to
the functionality and limitations of the 6
collection. Tuple, set and dictionary are the [6] = 'python'
#this will replace the value at the index
other collection data type in Python. A list is
6
ordered and changeable, unlike strings. We mylist.append('edureka')
can add duplicate values as well. To declare a #this will add the value at the end
list, we use the square brackets. mylist.insert(5, 'data science')
#this will add the value at the index 5
4.4 Tuple
Tuple is an ordered data structure whose #declaring o tuple
mytuple = (10,10, 20, 30, 40, 50)
values can be accessed using the index values.
#counting total number of elements
It can have duplicate values. To declare a
mytuple.count(10)
tuple, we use the round brackets. A tuple is a #to find an item index
read-only data structure and you cannot mytuple.index(50) #output will be 5
modify the size and value of the items of a
tuple.
4.5 Set
myset = { 10, 20 , 30 , 40, 50, 50}
A set is a collection that is unordered &
#to add a value in a set
doesn't have any index. To declare sets in myset.add('edureka')
Python, we use curly brackets. A set does not #to add multiple values in a list
have any duplicate values. Even though it will myset.update([ 10, 20, 30, 40, 50])
not show any errors while declaring the set, #to remove an item from a set
the output will only have distinct values. myset.remove('edureka')
Chapter 5
FLOW OF 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
CONTROL smarter code. After all, that is what coding is. Finding logic and solutions to
problems and can be done using Conditional and Iterative statements.
S I
statements accordingly. code that executes if the TRUE and execute a
A program can have conditional expression in block of code as soon as
many if statements. E the 'if statement' is FALSE. F one of the conditions
returns TRUE
5.2 Example
a = 10
b = 15
if a == b:
print ( 'They are equal' )
elif a > b:
OUTPUT: b is larger
print ( 'a is larger' )
else :
print ( 'b is larger' )
Loops in Python or any other language 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 condition is 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
FOR #syntax
for variable in range: statements
#example
This loop is used to perform
fruitsBasket= ['apple', 'orange', 'pineapple',
a certain set of statements 'banana']
for a given condition and for fruit in fruitsBasket:
continue until the condition print(fruit, end=',')
has failed #Output is apple, orange, pineapple, banana
#syntax
WHILE
while (test expression): statements
#example
second = 5
This loop in Python is used to while second >= 0:
iterate over a block of code print(second, end='->')
or statements as long as the second-=1
test expression is true. print('Blastoff!')
#Output is 5->4->3->2->1->Blastoff!
Chapter 6
OBJECT-ORIENTED
PROGRAMMING IN PYTHON
Object-Oriented Programming (OOP) is a way of computer programming 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.
#syntax
class EduClass():
Objects are an instance of a class. It is an entity that has 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')
class Employee(ABC):
Abstraction is used to simplify complex reality by @abstractmethod
modeling classes appropriate to the problem.
Here, we have an abstract class that cannot be def calculate_salary(self,sal):
pass
instantiated. This means you cannot create
objects or instances for these classes. It can only class Developer(Employee):
be used for inheriting certain functionalities
which you call a base class. So you can inherit def calculate_salary(self,sal):
functionalities but at the same time, you cannot finalsalary= sal*1.10
return finalsalary
create an instance of this particular class. Let’s
understand the concept of abstract class with an emp_1 = Developer()
example. print(emp_1.calculate_salary(10000))
#OUTPUT - 11000.0
6.3 Inheritance
class employee:
num_employee=0
Inheritance allows us to inherit attributes and
raise_amount=1.04def
methods from the base/parent class. This is useful __init__(self, first, last, sal):
as we can create sub-classes and get all of the self.first=first
functionality from our parent class. Then we can self.last=last
overwrite and add new functionalities without self.sal=sal
self.email=first + '.' + last
affecting the parent class. A class that inherits the + '@company.com'
properties is known as Child Class whereas a employee.num_employee+=1def
class whose properties are inherited is known as fullname (self):
Parent class. return '{}
{}'.format(self.first, self.last)
def apply_raise (self):
TYPES OF INHERITANCE self.sal=int(self.sal *
raise_amount)
Single Inheritance class developer(employee):
pass
Multilevel Inheritance
emp_1=developer('maxwell', 'sage',
Hierarchical Inheritance 1000000)
Multiple Inheritance print(emp_1.email)
#OUTPUT - maxwell.sage@company.com
6.5 Polymorphism
Polymorphism in Computer Science is the ability
to present the same interface for different class Animal:def __init__(self,name):
underlying forms. Polymorphism means that if self.name=name
class B inherits from class A, it doesn’t have to
def talk(self):pass
inherit everything about class A. It can do some of
the things that class A does differently. It is most class Dog(Animal):def talk(self):
commonly used while dealing with inheritance. print('Woof')
Python is implicitly polymorphic, it has the ability class Cat(Animal):def talk(self):
to overload standard operators, so that they have
print('MEOW!')
appropriate behavior based on their context.
c= Cat('kitty')
#OUTPUT - Meow!
Run-Time
Run-Time Polymorphism
Polymorphism 2 #OUTPUT - Woof
Chapter 7
Chapter 8
FREQUENTLY
ASKED
INTERVIEW
QUESTIONS
Today Python has evolved as the most preferred
language and considered to be the “Next Big Thing” and
a “Must” for Professionals. This chapter covers the
questions which will help you in your Python Interviews
and open up various Python career opportunities
available for a Python programmer.
www.edureka.co/python-programming-certification-training
www.edureka.co/data-science-python-certification-course
www.edureka.co/masters-program/python-developer-training
www.edureka.co/pyspark-certification-training
LEARNER'S REVIEWS
2500+ Technical
Blogs
3000+
Video Tutorials on
YouTube
30+
Active
Free Monthly
Community Webinars
WWW.EDUREKA.CO/PYTHON
About Us
There are countless online education marketplaces on the internet. And there’s us. We
are not the biggest. We are not the cheapest. But we are the fastest growing. We have
the highest course completion rate in the industry. We aim to become the largest
online learning ecosystem for continuing education, in partnership with corporates
and academia. To achieve that we remain ridiculously committed to our students. Be it
constant reminders, relentless masters or 24 x 7 online technical support - we will
absolutely make sure that you run out of excuses to not complete the course.