Day 21 Python Assignment
Day 21 Python Assignment
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.
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 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.
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.
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.
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.
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.