Python programming Concepts (Functions, classes and Oops concept

LipikaSharmaShrivast 52 views 16 slides Aug 28, 2024
Slide 1
Slide 1 of 16
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16

About This Presentation

Module 3: Introduction to Python for Data Science


Slide Content

Introduction to Python for Data Science

Replay Module 2 :Overview of Data Science Tools and Technologies Introduction to popular data science tools such as R Introduction to popular data science tools such as SQL Overview of machine learning algorithms and their applications

Session 7:Python programming Concepts Python Advance Topics Functions Classes Objects Methods Constructor OOPS Inheritance Encapsulation Polymorphism Abstraction

Functions with no arguments Python Functions  is a block of statements that return the specific task. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over and over again.

Use function arguments in Python Information can be passed into functions as arguments.  Arguments are specified after the function name, inside the parentheses . You can add as many arguments as you want, just separate them with a comma. A parameter is the variable listed inside the parentheses in the function definition. An argument is the value that are sent to the function when it is called. The terms parameter and argument can be used for the same thing: information that are passed into a function .

OOPS O bject-Oriented Programming (OOPs) is  a programming paradigm that uses objects and classes in programming . OOPs, concepts in python, aim to implement real-world entities like inheritance, polymorphisms, encapsulation, etc., in the programming. The concept of OOP in Python focuses on  building efficient and reusable code . This is also known as DRY (don't repeat yourself). 

How to Create a Class in Python A Class is like an object constructor, or a "blueprint" for creating objects. A class is created using the keyword class. Attributes refer to variables that belong to a class. These attributes are always public, and you can access them using a dot (.).  class   ClassName :     #statement_suite    # Declare an object of a class    object_name  =  ClassName (arguments)   

Method and Constructor in Python Methods are essential components of Python object-oriented programming (OOP) as they encapsulate the functionality associated with the objects.  Method Class Games: X=100 Def value(self): print( self.X ) Obj=Games() Obj.value () Constructors are generally used for instantiating an object. The task of constructors is to initialize(assign values) to the data members of the class when an object of the class is created. In Python the __ init __() method is called the constructor and is always called when an object is created. Constructor class Games: # default constructor def __ init __(self): print(“welcome”) # creating object of the class obj = Games()

Inheritance Inheritance is the capability of one class to derive or inherit the properties from another class. The class that derives properties is called the derived class or child class and the class from which the properties are being derived is called the base class or parent class.

Encapsulation Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the idea of wrapping data and the methods that work on data within one unit. This puts restrictions on accessing variables and methods directly and can prevent the accidental modification of data. To prevent accidental change, an object’s variable can only be changed by an object’s method. Those types of variables are known as private variables. A class is an example of encapsulation as it encapsulates all the data that is member functions, variables, etc.

Polymorphism Poly ' means multiple and ' morph ' means forms. So, polymorphism altogether means something that has multiple forms. Or, 'some thing' that can have multiple behaviours depending upon the situation. Polymorphism in OOPS refers to the functions having the same names but carrying different functionalities. Or, having the same function name, but different function signature(parameters passed to the function).

Abstraction Abstraction just shows us the functionalities anything holds, hiding all the implementations or inner details. The main goal of  Abstraction  is to hide background details or any unnecessary implementation about the data so that users only see the required information. It helps in handling the complexity of the codes. A bstraction can be achieved by using  abstract classes A class that consists of one or more  abstract methods  is called the " abstract class ". Abstract class can be  inherited by any subclass . The subclasses that inherit the abstract classes provide the implementations for their abstract methods. Abstract classes can act like  blueprint to other classes , which are useful when we are designing large functions. And the subclass which inherits them can refer to the abstract methods for implementing the features.

Q N A

Q What are access specifiers? What is their significance in OOPs?

Q How is an abstract class different from an interface?

Q How much memory does a class occupy?