-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions_notes_2_starter.py
More file actions
32 lines (21 loc) · 1.16 KB
/
functions_notes_2_starter.py
File metadata and controls
32 lines (21 loc) · 1.16 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
30
31
32
"""
Name:
Title: Scope and Encapsulation
"""
# SCOPE defines the accessibility of separate parts of a program. Functions
# have a local scope by default, which means variables (including parameters)
# initialized within a function are LOCAL VARIABLES, and only exist within that particular function.
# GLOBAL vs. LOCAL SCOPE
# GLOBAL VARIABLES initialized outside of functions are accessible throughout
# a program, and therefore have a global scope.
# Global Reach Example - demonstrates global variable access
# define functions
# Shadowing - When a local variable has the same name as a global variable we say that the local shadows the global.
# A shadow means that the global variable cannot be accessed by Python because the local variable will be found first.
# This is another good reason not to use global variables.
# main program
# ENCAPSULATION - Keeps code logically independent by ‘hiding’ information from other parts of a program.
# Functions should be written to leverage encapsulation and therefore only rely on local variables (if possible).
input("Press enter to continue.")
# MAIN FUNCTION
# encapsulates main program