Lecture 4 – Functions

Introduction

The true power of programming is opened up when you start defining functions. But before you start to define functions you should have a basic understanding of scope. Here is a video that will help you get started.

With the code from the video.

def AddToVariable(x):
    x = x + 1
    print("Local x: {}".format(x))
    return x

d = 1
e = AddToVariable(d)
print("d: {} e: {}".format(d,e))

x = 1
y = AddToVariable(x)
print("x: {} y: {}".format(x,y))

More on Functions

This will take you through some practical uses of functions in engineering and how to use them.