Changes

Jump to: navigation, search

OPS445 Online Lab7

33 bytes added, 12:46, 10 March 2022
m
Investigation III - Objects and Scope
: Try the following code. Have each in a separate Python file.
: '''Local scope(lab7g.py)''': <source lang="python">
#!/usr/bin/env python3
# Student ID: [seneca_id]
: Sometimes you want to have an object accessible from anywhere in your program, including inside and outside any functions. Here's an example:
:1. '''Global scope(lab7h.py)''': <source lang="python">
#!/usr/bin/env python3
# Student ID: [seneca_id]
:3. Python has one weird quirk when it comes to global scope: if you assign something to an existing object inside a function - it will assume you want to create a new object in that function's local scope. That will hide the global object inside the function unless you declare it explicitly with the global keyword:
:4. '''Global keyword(lab7i.py)''': <source lang="python">
#!/usr/bin/env python3
# Student ID: [seneca_id]
572
edits

Navigation menu