Python: Typs of Argument


Programming languages allow controlling the ordering and default values of arguments. In python we will observe the following in different cases:

Case 1: Positional

This is default way of specifying arguments. In this, the order, count and type of actual arguments should exactly match that of the formal arguments. Else it will result error.

Python: Positional Argument

Case 2: Keyword

This allow flexibility in the order of passing the actual arguments by mentioning the argument name.

Python : Keyword in argument

Case 3: Default

This allows the specify default value for an argument in the function signature. It is used only when no value is passed for the arguments else it works normally. In Python, default arguments should be last in the order.

Python: Default Argument

Case 4: Variable argument count

This allows a function to have variable number of arguments. In Python, any argument name starting with ‘*’ is considered to be a vary length argument. It should be last in order, It works by copying all values beyond that position in a tuple.

Python: Variable argument count

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s