Functions
By Sayantan Das
Youth Career Hub
,What is function?
●
A function is a block of code which only runs when it is called.
●
A function is a block of code that performs a specific task.
●
It is defined using the def keyword.
●
We can pass data, known as parameters/arguments into a function.
●
A function can return data as a result.
●
Functions allows us to encapsulate code logic into reusable units.
, What is method?
●
A method is similar to a function but is associated with an object
●
Methods are defined within classes.
●
It is also defined using the def keyword.
●
A method definition always includes self as its first parameter.
●
A method can operate on the data (instance variables) that is
contained by the corresponding class
●
Method also allows us to encapsulate code logic into reusable units.
By Sayantan Das
Youth Career Hub
,What is function?
●
A function is a block of code which only runs when it is called.
●
A function is a block of code that performs a specific task.
●
It is defined using the def keyword.
●
We can pass data, known as parameters/arguments into a function.
●
A function can return data as a result.
●
Functions allows us to encapsulate code logic into reusable units.
, What is method?
●
A method is similar to a function but is associated with an object
●
Methods are defined within classes.
●
It is also defined using the def keyword.
●
A method definition always includes self as its first parameter.
●
A method can operate on the data (instance variables) that is
contained by the corresponding class
●
Method also allows us to encapsulate code logic into reusable units.