Can anyone explain clearly what is the main difference between class, object, instance of class, function,method, attribute,variables in python.Explain with an example?

Can anyone explain clearly what is the main difference between class, object, instance of class, function,method, attribute,variables in python.Explain with an example?

IN PYTHON
1.CLASS & OBJECT: A Class is like an object constructor, or a “blueprint” for creating objects While everything in Python is an object, with its properties and methods.
eg of class:class
MyClass:
x = 9

print(MyClass)
eg of object:

class MyClass:
x = 9

y = MyClass()
print(y.x)
2.function:
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.
eg:
def my_function():
print(“Hello this is my function”)

my_function()
3.variable:
Variables are containers for storing data values.
Unlike other programming languages, Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
eg: x = 9
y = “You”
print(x)
print(y)``
4.Attribute
attributes are variables of a class that are shared between all of its instances. They differ from instance attributes in that instance attributes are owned by one specific instance of the class only, and ​are not shared between instances.
5.Method
A method in python is somewhat similar to a function, except it is associated with object/classes. Methods in python are very similar to functions except for two major differences.

  • The method is implicitly used for an object for which it is called.
  • The method is accessible to data that is contained within the class.

for better understanding you should go with this website:Click Here

1 Like