-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment_3.py
More file actions
29 lines (16 loc) · 1.75 KB
/
Copy pathAssignment_3.py
File metadata and controls
29 lines (16 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
1. Functions are advantageous to have in your programs because they allow you to reuse code, improve code organization and readability, and make it easier to debug and maintain your program.
2. The code in a function runs when the function is called, not when it is specified.
3. The `def` statement creates a function.
4. A function is a named block of code that can take arguments, perform some operations, and optionally return a value. A function call is the act of executing the code within the function.
5. In a Python program, there is one global scope and multiple local scopes (one for each function).
6. When a function call returns, the variables in the local scope of that function call are destroyed.
7. The concept of a return value is that a function can send data back to the caller. Yes, it is possible to have a return value in an expression.
8. If a function does not have a return statement, the return value of a call to that function is `None`.
9. To make a function variable refer to the global variable, you use the `global` keyword inside the function.
10. The data type of `None` is `NoneType`.
11. The sentence `import areallyourpetsnamederic` would attempt to import a module named `areallyourpetsnamederic`, but this is not a valid module name and would result in an `ImportError`.
12. If you had a `bacon()` feature in a `spam` module, you would call it as `spam.bacon()` after importing the `spam` module.
13. To save a program from crashing if it encounters an error, you can use a `try`/`except` block to catch and handle the exception.
14. The purpose of the `try` clause is to enclose the code that might raise an exception. The purpose of the `except` clause is to handle the exception if it is raised.
"""