Python Flashcards
Tuples
- immutable objects
- start at 0
- can lookup but can’t change
- more efficient but less flexible
Lists
- mutable
- zero based
- can be very flexible and has many functions
Strings
“”
Zero index
Immutable
Reference Semantics
When assign var to another var it point to address
- Reference of name X is looked up
- The value at that reference is retrieved
- Calculation occurs producing new data element which is assigned to fresh memory location with new reference
- The name X is changed to point to this new reference
- Old data is garbage collected if no var still refers to it
- Reference of name X is looked up
LEGB
- First search for local definition
- And if not found there go to Enclosing definition
- Not found there go to Global definition
- If not there then go to Built-in definition
Local (function)
Names assigned in any way within a function and not declared global in that function
Enclosing function locals
Names in the local scope of any and all enclosing functions from inner to outer
Global (module)
Names assigned at the top level of a module file or declared global in def within the file
Built-in (python)
Names preassigned in the built in names module
Class
Is a special data type which defines how to build certain kind of object
-stores some data items that are shared by all the instances of this class
Instances
Are objects that are created which follow the definition given inside the class
Data attribute
- var owned by a particular instance of a class
- each instance has its own value for it
- these are the most common kind of attribute
Class attributes
- owned by the class as a whole
- all instances of the class share the same value for it
- called “static” var
First-object
- an argument to a function
- a return value from a function
- assigned to a variable
- a part of container (tuple, list)