method vs function python-types of method-class in python

method vs function python :

Welcome to my article, In this article we are going to see What is method vs function  in python.
before going towards this post if you want to learn python for free then click on  python tutorials point.

Difference between Python Methods vs Functions


METHODSFUNCTIONS
Method definition are always present inside the classes.We don not need a class to define a functions.
Method are associated with the object of the classes they belong to.but Function are not associated with any objects.
For method We cannot invoke it is just by its nameWe can invoke a functions just by its name.
Method can operate on the data of the objects they associate with itFunction operate on the data you pass to them as a argument.
Method is dependent on the class they belong to.Function is independent entities in a program.
A methods requires to have ‘self’ as it first arguments.Function do not require any ‘self’ arguments. 

 Java is also an Object Oriented Programming language, but their is no concept of Functions in it. But Python has both concept of Methods and Functions. https://www.python.org/
Hence key differences between Method and Function in Python are explained.
method vs function python-types of method
fig 01) method vs function python-types of method-class in python

A) Python Method
Method are associated with the object of the classes they belong to
A methods requires to have ‘self’ as it first arguments.
It may or may not return any data
A method can easily operate on the data (instance variable) that is contained by the corresponding classes.
Method is dependent on the class they belong to
Method definition are always present inside the classes.

Basic Program for Method in python : 
class class_name 
def method_name () : 
////////////////////////
# method body for code
///////////////////////////////////
Python For User-Defined Method :


class PYTHON : 
def method_python (self): 
print("I am in method_python of PYTHON class. ") 

class_ref = PYTHON() # object of PYTHON class 
class_ref.method_python() 
Output:

 I am in method_python of PYTHON class



Python  Inbuilt method :
import math 
ceil_val = math.ceil(14.75) 
print( "posting value of 14.75 is are : ", ceil_val) 
Output:
posting value of 14.75 is are:  15

B) python Function :
  1. Functions is block of code that is also called by it is name
  2. The functions can have different parameters and may not have any at all. If any data  are passed, they are passed explicitly in order.
  3. It may or may not return any data.
  4.  But Function does not deal with Classes and its instance concepts.
Basic Function Structure in Python :
def function_name ( arg1, arg2, ...) : 
...... 
# function body for program
...... 
Python For User-Defined Function :

def Sub (a, b): 
return (a-b) 

print( Sub(9, 12) ) # prints -3

print( Sub(16, 6) ) # prints 9 
Output:
-3
10
Python For Inbuilt Function :
sach = sum([15, 15, 2]) 
print( sach ) # prints 32 

mx = max(13, 6) 
print( mx ) # prints 13 
sach = sum([15, 15, 2]) 
print( sach ) # prints 32 

mx = max(13, 6) 
print( mx ) # prints 13 

Summary

Finally We can conclude that Method and Function are concept are very similar and hence this are ask multiple time in MCQ. In a nutshell concept, both method and function perform task and may return some amount value. But the difference lies in the fact that method are ‘associated’ with object, while function are not used.
For similar kind of post click on pythonslearning and if you like this post then please comment and share.
Best of luck !!!!
Tags: method vs function python,methods in python 3, types of methos in python,Difference between methods and function.
Some information about FAQ:

1) python procedure vs function :

Function must return a specific values but in Stored Procedure and it is optional: The procedure can returns 0 or n value. Function can have only input parameters, But procedure have both input/output parameter.
2) types of method in python
There are three different types of  method in python
1.The static method
2.The class method
3. The instance method
3)  difference between class and function in python
There is a Small  difference between a Class and a Functions in python and it is just not only in the python it is there in every Oop Language.  A class is basically a definition of an Objects. While a function is a small piece of code. 

Previous
Next Post »

comparison python vs r vs sas vs spss

python  vs r vs sas vs spss : Welcome everyone, Today we will see comparison between  r vs python vs sas vs spss . So Let's start : ...

Get Free Crash Course Subscription Valid Only For 10000 Subscriber.

Enter your email address:

Delivered by FeedBurner