0% found this document useful (0 votes)
57 views10 pages

Name: Aniket Subhash Darade Subject: Python Programming Teacher: Tejashree Ma'Am Standard: Sy BSC It ROLL NO: 197032

This document discusses Python object-oriented programming concepts including instances as arguments, instances as return values, built-in class attributes, and inheritance. It provides examples of passing an object as an argument to a function, returning an instance from a method, and built-in class attributes like __dict__, __doc__, and __name__. Inheritance in Python allows a derived class to acquire properties from its parent class, and examples demonstrate checking if an object is an instance of a class or if one class is a subclass of another.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
57 views10 pages

Name: Aniket Subhash Darade Subject: Python Programming Teacher: Tejashree Ma'Am Standard: Sy BSC It ROLL NO: 197032

This document discusses Python object-oriented programming concepts including instances as arguments, instances as return values, built-in class attributes, and inheritance. It provides examples of passing an object as an argument to a function, returning an instance from a method, and built-in class attributes like __dict__, __doc__, and __name__. Inheritance in Python allows a derived class to acquire properties from its parent class, and examples demonstrate checking if an object is an instance of a class or if one class is a subclass of another.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 10

NAME : ANIKET SUBHASH DARADE

SUBJECT : PYTHON PROGRAMMING


TEACHER: TEJASHREE MA’AM
STANDARD : SY BSC IT
ROLL NO : 197032
TOPICS
■ Instances as Arguments,
■ Instances as return values,
■ Built-in Class Attributes,
■ Inheritance
Instances as arguments

We can pass an object as an object as an argument in the


usual way. It uses function notation
Instance variables are always prefixed with the reserved
word self. They are typically introduced and initialized in
constructor method named __init__ .
Its also know as class instantiation.
Instances as return values
It means the method create an object using the constructor
and then return it as the value of the method

Example:
class example(object):
def __init__(self,intputs):
self.out = inputs
... instance = example(inputs)
Built_in class attributes

■ What are built_in class attributes ?


Sr No. Built_In Class Description
Attribute
1 __dict__ Dictionary contains the class’s namespace.
2 __doc__ Class documentation string or none, if undefined.
3 __name__ It is a class name
4 __module__ It is a Module name in which the class is defined.
This attribute is”__main__” in interactive mode.
5 __bases__ It is possibly an empty tuple that contains the base
classes, in the order of their occurrence in the
base class list.
Inheritance
Python uses inheritance, which helps to acquire the information from the parent
class.
■ Syntax:
class BaseClass:
Body of base class Body of derived class.
class DerivedClass(BaseClass):
Body of derived class.
Example:

class Person(object):
    def __init__(self, name):
        self.name = name
    def getName(self):
        return self.name
    def isEmployee(self):
        return False
class Employee(Person):
    def isEmployee(self):
        return True
emp = Person("Geek1") 
print(emp.getName(), emp.isEmployee())
    emp = Employee("Geek2")
print(emp.getName(), emp.isEmployee())
output:
True
False
THERE ARE TWO INBUILT PYTHON
FUNCTION FOR INHERITANCE :

1. Isinstance()
2. Issubclass()
1. Isinstance()
This function is used to check the type of instance.
For example: isinstance(obj,int)
This function will return the true value if obj.class is of int type or some
class derived from the int.

2. Issubclass()
This function is used to check the class inheritance.
For example: issubclass(bool,int)
■ This function will return the true value if bool is a subclass of type
int.
Thank You

You might also like