Skip to content
Permalink
Browse files
commiting changes before I mess with stash issues.
  • Loading branch information
Barnsa committed Jul 23, 2020
1 parent 3cf8f8c commit 689d0e07e48ea03b0171d3ea5e948a1c7787adc7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
# into-example.py
# Displaying scope as a call to a variable

variable_1 = 70

def add_two(number):
result = number + 2
print(f"the square of {number} is: {result}")

add_two(variable_1)

try:
print("testing functions...")
# this isn't accessable from outside the square() function
print(result)
print(base)
except NameError:
print("These functions aren't in scope")


# NOTE!! This code is heavily mentioned in the markdown file "intro-to-functions.md"
# if you change it here then you may mess something up there.
@@ -1,13 +1,49 @@
# Functions
Functions are the way in which we encapsulate code so that it can be reused multiple times. Sometimes this is in a single program and other times it's to include inside our own custom library.
Functions are the way in which we encapsulate code so that it can be reused multiple times. Sometimes this is in a single program and other times it's to include inside our own custom library.

Any time code needs to be executed or evaluated in the same way, it can also be passed into a function to have the same process done to it. By passing functions to functions we can build up any complex arrangement you can think of, and is how all modern programs are constructed.

Some functions inside python are built in functions that do a specific job or exhibit a specific behaviour. There are also ways to perform small inline functions in this manner. This will be covered in the [built in functions](built-in-functions/README.md) section.
Some functions inside python are built in functions that do a specific job or exhibit a specific behaviour. There are also ways to perform small inline functions in this manner. This will be covered in the [built in functions](built-in-functions/README.md) section. Let's look at some of the reasons we use functions in more depth:

## Scope
Scope is the technical term for if python can see a variable or function at any point in your program. As scope is one of those things that makes more sense when you see it, consider this example:

{{ code_from_file("functions/intro-example.py", 2, 20, execute=true) }}

!!! Example
In this example, you can see that we have created a variable named "variable_1" and we have created a function using the key word "def", for more information on creating variables you can find it [here](functions/user-functions/README.md) in the user functions section.

## Abstraction and reusability

## Modularity



## Outline
outline user defined
- abstraction and reusability
- modularity
- namespace separation
- how a function is called and how it is defined
- passing arguments
- keyword argument rules
- mutable default parameters
- pass by value and pass by reference
- return statement
- side effects
- variable length argument lists
- tuple packing and unpacking
- dictionary packing and unpacking
- docstrings
- dunders
- function annotations

outline built-in functions
- generators
- yield
- lambda
- map
- Special mentions
- any
- exec
- print
@@ -14,27 +14,3 @@ def name_of_function(passed_variable):
```
The contents of the function is always indented to show that it belongs to the function definition above it.

outline user defined
- abstraction and reusability
- modularity
- namespace separation
- how a function is called and how it is defined
- passing arguements
- keyword arguement rules
- mutable default parameteres
- pass by value and pass by reference
- return statement
- side effects
- variable length arguement lists
- tuple packing and unpacking
- dictionary packing and unpacking
- docstrings
- dunders
- function annotations

outline built-in functions
- generators
- yeild
- lambda
- map
-
@@ -70,7 +70,7 @@ In this example, the data is stored in a tuple and then unpacked for use in the
This brings us nicely onto the other way to use tuples, as immutable lists. The reason you use tuples as immutable lists is so that you can use slicing and other list functionality that also works with tuples, but without the fear of someone else in your production team modifying the list by accident. Another way to store data as records is to store it as a dictionary.

### Dictionary
Dictionaries are an interesting data structure, its used to store data in key value pairs so that you can easily access the data by label instead of by index value. This is especially helpful if you want to dynamically create a csv file or know you need to store categorised data throughout a program, but other people are in charge of much of the data input. Dictionaries always have this form:
Dictionaries are an interesting data structure, its used to store data in key value pairs so that you can easily access the data by label instead of by index value. This is especially helpful if you want to dynamically create a csv file or know you need to store categorised data throughout a program but other people are in charge of much of the data input. Dictionaries always have this form:

```python
d = {
Submodule mk_doc_ultra updated 3 files
+102 −0 README.md
+45 −4 main.py
+4 −0 mk_ultra.css

0 comments on commit 689d0e0

Please sign in to comment.