Newby Coder header banner

Parameters

Function parameter or arguments

Parameters are variables, used in a function which are provided as input to function when called

The behaviour of a function can depend on the parameters accepted by it

A function might be defined with one or more parameters

Function parameters are the names listed in the function definition

Parameters vs Arguments

Function arguments(or actual parameters are the real values passed to (and received by) the function when executed

For example

def square(x):
    x

In the above example, x is a parameter

And when the function is called with a value such as square(12) then the value 12 is the argument

Also in the case

a = 15
square(a)

a is the argument

  • Sometimes the terms parameter and argument are used interchangeably
  • Type of parameters

    In strongly typed language such as Java, the data type of a parameter has to be specified during function definition

    In a dynamically typed language type of a variable is determined during run time

    In Python, which is a dynamically typed language, data types are associated with the values, and the variables only act as reference to the value

    Call by Reference vs Call By Value

    Parameters can be categorised based on whether the value is passed to the function or a reference to the (memory address of the) object or value is passed