Posts

Showing posts with the label Functions and Function parameters

Python Programming Language - Functions and Function parameters

Image
A function is a block of code that can be utilized again in other areas of the program once it has completed a particular task. The functions have already been utilized in earlier articles. Specifically, the print() function, which outputs a value to the console. Python lets you define your own functions and includes a large library of built-in functions. Formal definition of a function: def function_name ([parameters]):     instructions A function definition begins with an expression def, which consists of the function name, a set of parentheses with parameters, and a colon. Parameters in parentheses are optional. And from the next line there is a block of instructions that the function executes. All function instructions are indented from the beginning of the line. For example, the definition of the simplest function: def print_hello():     print( "Hello" ) The function is called print_hello. It has no parameters and contains one single instruction, which prints the strin