Object oriented programming
Object in python can be thought of as any object in the real world ,
Lets say a mug
Now lets see what all can be associated with a mug :
1. Identity :- it can be a coffee mug , a tea cup , etc
2. Attributes /properties :- like its color ,fullness , size
3. Behavior:- fill() , empty(),clean() [things you can actually do with a cup ,]
Like each mug is different ,even if you brought 2 of them , each object is different from one another . …
‘’’ Inheritance: In basic English Inheritance is the concept of qualities being passed from one generation to another.
similarly in classes the variables and methods of the parent class are passed on to the child class
example :let us consider a family‘’’
language = “English”
nationality = “Indian”
print(“country of origin is India”)
‘’’Here we have created a class called Grandfather , now as we know few properties/characteristics of Grandfather are
passed on in generations . …
'''Method : they are just like functions ,here the method takes is an object as its parameter
constructor : it is a __init__ function , which is automatically called/executed when the class is called .
the constructor as the name suggests , constructs attributes of the object for a class .
in simple words , here objects are given values . similar to variable assignment , but just in a more systematic manner
def __init__(self,aname,asalary,adepartment,aage):# this is a constructor
# assigning values to instance (object) variables…
'''Decorators are the functions that add some functionalities to a given function. they don't change the function/structure of the function but just add a few lines of code below and after the function .
A wrapper is a function that provides a wrap-around another function. While using decorator ,all the code which is executed before our function that we passed as a parameter and also the code after it is executed belongs to the wrapper function. The purpose of the wrapper function is to assist us.
def dec1(func): # this is a decorator
def executor(): # this is a wrapper function
#WHAT IS IMPORT ??
'''In Python, we get access to using a module by importing it .
to do this we use the keyword import '''
#HOW IMPORT FUNCTION WORKS??
'''when we write a module name with the keyword import , it starts searching for the module name along with the
extension .py after finding the file , it will import it into our program . …
MAP ,FILTER AND REDUCE
Map ,Filter and reduce are three functions that can be used for convenience
all the functions have a similar syntax
lets take examples of all the three
Map function operates the function on the iterable (in this case list1) and return an object
since Map function returns an object , here we have converted the object into a list .
lambda function is used to convert all strings into integer
x = list(map(lambda x:int(x),list1))
#[25, 29, 58]
'''filter function takes a function as first argument and iterable as the second , it filters all the values , which
are true after…
local and Global scope of variables
Scope of a variable is defined as the area with in which the variable is accessible.
variable is a label for a location in the memory.
Not all variables are accessible, and not all variables exist for the same amount of time.
types of variables:
variables can be local and global
local variables are the variables that can be accessed in a local scope .ie with in the respective loop/function/if-else statement etc
global variables are the variables that can be accessed in globally
print("case 1 " , a)
A file is a resource that is used for saving data and information in the hardware of the computer
there are various mode of opening a file
r : r mode opens a file for read-only. We do not have permission to update or change any data in this mode.
w : w mode does not concern itself with what is present in the file. It just opens a file for writing and if there is
already some data present in the file, it overwrites it.
x : x is used to create a new file. It does…
First let us learn what an exception is:-
exception is an error that is not a syntax error but an error caused by our mistake .
Exception can be said as an error, that causes a program to crash. Unlike syntax error,
it is syntactically correct and occurs mostly due to our negligence
For example, assigning a string value to an int data type variable or
dividing a number by zero or also when a name of a variable or a function is not found, an exception occurs.
#try and exception handling is used so that the program does not crashes ,instead an error…