Let's start with C. Please be remembered that most of the posts are posted for my purpose as I don't get much time. So, you will not be able to get the full picture of each topic from the posts though some might sound informative and coherent.
I always believe the power of the function is when it is only called.
Function Definitions, Invocation, & Prototype in C
Definition
<data type> function-name (<data-type> argument1, <data-type> argument2)
{
....
Blah...Blah...
.....
}
Calling/Invocation
<data-type> variable = function-name(argument1, argument2)
Prototype
<data type> function-name (<data-type> argument1, <data-type> argument2)
Function Definitions in Python
Definition
def function-name (argument1, argument2) :
.....
Blah...Blah...
.....
Invocation
Arbitrary Arguments
Definition
def function-name (*argument) :
.....
Blah...Blah...
Invocation
Keyword Arguments
Arguments can be passed as key = value syntax. In this case, the order doesn't matter.
Definition
def function-name (argument1, arguement2, argument3) :
.....
Blah...Blah...
Invocation
Arbitrary Keyword Arguments
If we are not sure of how many keyword arguments to be passed into the function, we can add ** before the argument in the function definition.
Definition
def function-name (**argument) :
.....
Blah...Blah...
Invocation
Default Parameter Value
If the function is called without an argument, it uses the default value.
Definition
def function-name (argument = "Shirley") :
.....
Blah...Blah...
Invocation
Passing a list as an argument
If the function uses list as an argument, it will treated as list in the function definition.
Definition
def function-name (names) :
for x in names:
print(x)
Invocation
Return value
If the function uses list as an argument, it will treated as list in the function definition.
Definition
def function-name (names) :
return 5 * x
Invocation
The pass statement
Function definition can't be empty, so if your intent to have empty function, don't forget to have pass statement
Definition
def function-name () :
pass
Recursive Function
To be updated........
Definition
def function-name () :
C++ will be updated when I learn...
Reference
w3schools
Comments
Post a Comment