0% found this document useful (0 votes)
41 views

Day 21 Python Assignment

Instance methods can access unique instance data through the self parameter. Class methods are bound to the class and know about the class through the cls parameter but not instances. Static methods are not dependent on the class or instance state. Instance variables are unique to each object while static variables are shared among all class instances and exist throughout program execution. Decorators in Python allow modifying function or class behavior without permanently changing them. Class methods can modify class state while static methods cannot access or modify class state. Inheritance enables defining a new class that extends an existing parent class and adds more functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Day 21 Python Assignment

Instance methods can access unique instance data through the self parameter. Class methods are bound to the class and know about the class through the cls parameter but not instances. Static methods are not dependent on the class or instance state. Instance variables are unique to each object while static variables are shared among all class instances and exist throughout program execution. Decorators in Python allow modifying function or class behavior without permanently changing them. Class methods can modify class state while static methods cannot access or modify class state. Inheritance enables defining a new class that extends an existing parent class and adds more functionality.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

>> Types of Methods

>>> Instance Methods

Instance methods are the most common type of methods in Python classes. These are so called because they can
access unique data of their instance. ... Self is another Python special term. Inside any instance method, you can use
self to access any data or methods that may reside in your class.

>>> Class Method

A class method is a method that is bound to a class rather than its object. It doesn't require creation of a
class instance, much like static method
The difference between a static method and a class method is:

 Static method knows nothing about the class and just deals with the parameters

 Class method works with the class since its parameter is always the class itself.

>>> Static Method

Static methods, much like class methods, are methods that are bound to a class rather than its object. They do not
require a class instance creation. So, they are not dependent on the state of the object.

>> What is the difference between instance and static variable?

Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the
object is destroyed. Static variables are created when the program starts and destroyed when the program
stops. Instance variables can be accessed directly by calling the variable name inside the class.

When we declare a variable inside a class but outside any method, it is called as class or static variable in python.
Class or static variable can be referred through a class but not directly through an instance.

>> What do you understand by decorators in python?

The decorator in Python's meta-programming is a particular form of a function that takes functions as input and
returns a new function as output. There are some built-in decorators viz: @classmethod. @staticmethod. @property.

Decorators are very powerful and useful tool in Python since it allows programmers to modify the behavior of function
or class. Decorators allow us to wrap another function in order to extend the behavior of the wrapped function, without
permanently modifying it.

>> What is the difference between static and class method in python?

A class method takes cls as first parameter while a static method needs no specific parameters. A class method can
access or modify class state while a static method can't access or modify it. In general, static methods know nothing
about class state. ... On the other hand class methods must have class as parameter.

>> What do you understand by staticmethod and classmethod in python?

Static methods, much like class methods, are methods that are bound to a class rather


than its object. They do not require a class instance creation. So, they are not dependent on
the state of the object.

A class method is a method which is bound to the class and not the object of the class. They have the access to the
state of the class as it takes a class parameter that points to the class and not the object instance. It can modify
a class state that would apply across all the instances of the class
>> Inheritance Programs

Inheritance enables us to define a class that takes all the functionality from a parent class and allows us to
add more. In this tutorial, you will learn to use inheritance in Python.

Inheritance is a powerful feature in object oriented programming.

It refers to defining a new class with little or no modification to an existing class. The new class is
called derived (or child) class and the one from which it inherits is called the base (or parent) class.

You might also like