Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 7

570 bytes added, 11:52, 3 December 2017
Global Scope
You may find that when you have more than one or two objects of a type - it will be easier to store them in a Python list instead of having separate variables for each of them. Again - which makes more sense depends entirely on what you do with your objects in your application in any particular situation.
To get you started, here's a template for a file you should name '''lab7a.py'''
<source lang="python">
Note that the function1() call does not modify the global '''authorName''' variable but function2() does.
As an exercise: modify the example above so that it would print the following, by changing only the scope of some variables. Save the program as '''lab7c.py''': <source>AndrewAndrew 1Andrew 1Andrew 2Andrew 1</source> == Object /Instance Scope == Every object can have variables that exist for that object only. You create and access those variables with the '''self.''' notation. Note that these are not '''class''' variables. Each object has its own set of '''instance''' variables. You will have seen that when you created objects in the Classes and Objects section above.
= LAB 7 SIGN-OFF (SHOW INSTRUCTOR) =