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 Object-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(argume nts)
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. • Abstraction 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?

Python programming Concepts (Functions, classes and Oops concept

  • 1.
    Introduction to Pythonfor Data Science
  • 2.
    Replay Module 2 :Overviewof 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
  • 3.
    Session 7:Python programming Concepts PythonAdvance Topics • Functions • Classes • Objects • Methods • Constructor • OOPS Inheritance Encapsulation Polymorphism Abstraction
  • 4.
    Functions with noarguments • 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.
  • 5.
    Use function argumentsin 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.
  • 6.
    OOPS Object-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).
  • 7.
    How to Createa 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(argume nts)
  • 8.
    Method and Constructorin 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()
  • 9.
    Inheritance • Inheritance isthe 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.
  • 10.
    Encapsulation Encapsulation is oneof 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.
  • 11.
    Polymorphism • Poly' meansmultiple 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).
  • 12.
    Abstraction • Abstraction justshows 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. • Abstraction 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.
  • 13.
  • 14.
    Q What areaccess specifiers? What is their significance in OOPs?
  • 15.
    Q How isan abstract class different from an interface?
  • 16.
    Q How muchmemory does a class occupy?