From fde32de3d521466338beee3120d3a84b047f169b Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Thu, 30 Jan 2025 12:26:33 -0700 Subject: Added Functions and Classes/Objects tutorial --- tutorials/3.x_Functions.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tutorials/3.x_Functions.md (limited to 'tutorials/3.x_Functions.md') diff --git a/tutorials/3.x_Functions.md b/tutorials/3.x_Functions.md new file mode 100644 index 0000000..e4c9874 --- /dev/null +++ b/tutorials/3.x_Functions.md @@ -0,0 +1,29 @@ +# Functions + +Like a traditional mathematical functions, python functions can take an input, process it, and give an output. Functions are blocks of code that is run everytime it's called. This allows us to re-use code. + +Functions are defined by using the def keyword. Reminder: it is important to indent all code inside the function to signify the end of the function. + +## Creating a function with no input +This is useful if you need to re-use code without having to copy paste the block. + +``` + def function_name(): + print("This is from a function") +``` + +## Creating a function with one input + +``` + def function(x): + print(x + " is best") +``` + +## Returning values from a function +Let's make a + +``` + def function(x, b): + y = 3*x+b + return y +``` -- cgit v1.2.3