Category: Functions

Functions

argmax and argmin

argmax and argmin

argminxf(x) is the value of x for which f(x) attains it’s minimum. argmaxxf(x) is the value of x for which f(x) attains it’s maximum. In Python ARGMIN AND ARGMAX returns Indices of the minimum...

Python time strftime() method

Python time strftime() method

The method strftime() converts a tuple or struct_time representing a time as returned by gmtime() or localtime() to a string as specified by the format argument. If t is not provided, the current time...

Typecasting in python

Typecasting in python

Casting is when you convert a variable value from one type to another. This is, in Python, done with functions such as int() or float() or str(). The various casting methods that are in...

Variable Scope

Variable Scope

The scope of an identifier is defined to be the portion of the program where its declaration applies, or what we refer to as “variable visibility.” In other words, it is like asking yourself...

Anonymous Functions and lambda

Anonymous Functions and lambda

Python allows one to create anonymous functions using the lambda keyword. They are “anonymous” because they are not declared in the standard manner, i.e., using the def statement. (Unless assigned to a local variable,...

Default Arguments

Default Arguments

Default arguments are parameters which are defined to have a default value if one is not provided in the function call for that argument. Such definitions are given in the function declaration header line....

Passing Functions

Passing Functions

The concept of function pointers is an advanced topic when learning a language such as C, but not Python where functions are like any other object. They can be referenced (accessed or aliased to...

Forward References

Forward References

Like some other high-level languages, Python does not permit you to reference or call a function before it has been declared. We can try a few examples to illustrate this: If we were to...

Creating Functions

Creating Functions

def Statement Functions are created using the def statement, with a syntax like the following: The header line consists of the def keyword, the function name, and a set of arguments (if any). The...

Calling Functions

Calling Functions

Function Operator Functions are called using the same pair of parentheses that you are used to. In fact, some consider ( ( ) ) to be a two-character operator, the function operator. As you...

Return Values and Function Types

Return Values and Function Types

Functions may return a value back to its caller and those which are more procedural in nature do not explicitly return anything at all. Languages which treat procedures as functions usually have a special...

What Are Functions

What Are Functions

Functions are the structured or procedural programming way of organizing the logic in your programs. Large blocks of code can be neatly segregated into manageable chunks, and space is saved by putting oft-repeated code...