SCRIPTS FUNCTIONS basicΒΆ

# -*-Python-*-
# Created by bgrierson at 01 Nov 2015  18:14

# Define a function of one variable
def fun(x):
    """
    This is a docstring for a function
    :param x: number or array
    :return: x squared
    """
    return x ** 2


x = 3.0
y = fun(x)
print('First function')
print(x)
print(y)


# Define a function with an optional parameter that has a default value
def fun2(x, p=2.0):
    return x + p


x = 2.0
y = fun2(x)
y2 = fun2(x, p=10.0)
print('Second function')
print(x)
print(y)
print(y2)