...

/

Creating and Calling a Function

Creating and Calling a Function

Learn how to create and call a function in Python and Powershell.

We'll cover the following...

Creating a Function

Before we can even use a function, we have to first define it with a name, a set of parameters, and the code block. This is called the function definition. Both Python and PowerShell follow different syntax and keywords, which are as follows.

Python Syntax:

def function_name (one or more comma separated parameters):
    "function docstring"
    function statements
    return <expression>

PowerShell Syntax:

function function_name (one or more comma separated parameters){
    <#
    .SYNOPSIS
    function help documentation
    #>
    function statements
    return <expression>
}

By default, both in Python and PowerShell parameters are positional, meaning that arguments will bind in the same order that they were defined. The following are a couple of rules to keep in mind when defining a function:

...