You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: labs/coding-103-python-json/6.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,12 @@
2
2
3
3
A function is a block of code that is run only when it's explicitly called. For example, print() is a function written in Python that you've called many times. Functions are written to modularize code to make it easy to read, easier to debug because it's located in one place and to reuse. Essentially, you don't want to write code over and over again that does the same thing. Instead you would put it into a function and then call that function whenever you need it.
4
4
5
-
Let's look at the structure of a function, then we'll look at a simple example. In Python a function is defined in the follow manner shown below. The keyword **def** specifies that a function is defined which is then followed by the name of the function and optional arguments that are passed into it.
5
+
Let's look at the structure of a function, then we'll look at a simple example. In Python a function is defined in the follow manner shown below. The keyword **def** specifies that a function is defined which is then followed by the name of the function and optional arguments that are passed into it.<br/><br/>
Let's look at some simple examples of functions. The first function named **my_function** simply prints a statement. The second function **brett** takes an argument called **val** which it passes to the function **range** and uses for looping.
Let's look at some simple examples of functions. The first function named **my_function** simply prints a statement. The second function **brett** takes an argument called **val** which it passes to the function **range** and uses for looping.<br/><br/>
Now let's look at these simple functions in a script to see how they're called. When this script is run, starting from the top of the script, the Python interpretor looks at what it should run now. It sees the call to print and executes that. It then sees the next two defined functions, makes note of them, but does not run them because they are not explicitly called. Continuing down the script it then sees the call to **function my_function** and executes it. Finally, it sees the call to **function brett** with the argument of 5 passed in and executes it.
14
13
```python
@@ -25,7 +24,8 @@ def brett(val):
25
24
my_function()
26
25
brett(5)
27
26
```
28
-
As a result the output occurs as shown below.
27
+
<br/><br/>
28
+
As a result the output occurs as shown below.<br/><br/>
@@ -112,7 +112,7 @@ You should see a result like the following. For purposes of brevity some record
112
112
113
113
114
114
## Give it a Try
115
-
* Open file **json_parse-1.py** . Create and call two functions that parse the JSON data. You may use the code you wrote in Step 5 to complete the functions. Run the code.
115
+
* Open file **json_parse-1.py** . write and call two functions that parse the JSON data. You may use the code you wrote in Step 5 to complete the functions. Run the code.
116
116
* Run the file \DevNetCode\<your-name>\coding-skills-sample-code\coding102-REST-python-ga\get-network-devices.py . Review the JSON data printed. Then open the file and modify it to print out other data. Run the code.
0 commit comments