1/20
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Value semantics and reference semantics
refer to how parameters are passed to a function
Value semantics
Behavior where variables store a value. When a
variable is passed as a parameter, the value of the actual parameter is
copied into the formal parameter.
Reference semantics
Behavior where variables store memory addresses
or locations of objects. When a reference is assigned or passed as a
parameter, the formal parameter refers to the same object as the actual
parameter.
variables of type… store values directly
ints, floats, booleans, strings, tuples
variables of object types store references to memory
lists, dictionaries, sets, panels
mutability
the ability to be changed or mutated
Immutable variables
ints, floats, strings, bools, tuples
Operations that try to change the value of an immutable object…
create a new object
Operations that change the value of a mutable object…
can change the object
Immutable
quicker to access, fundamentally expensive to “change” because doing so involves creating a new copy.
Mutable
relatively cheap to change because you are not creating a new copy
Lists and DrawingPanel
are mutable
Why are lists and objects mutable?
Efficiency and sharing
Efficiency
copying large objects slows down a program
Sharing
it’s useful to share an object’s data among functions
When a mutable object is passed as a parameter…
the function can change it
If the parameter is modified…
it will affect the original object
Lists are mutable
true
swap_all
accepts two lists of integers as parameters and swaps their entire contents. Assumes two lists are the same length.
Tuples are similar to a list but __ be altered
cannot (i.e., immutable)
Tuples
goods for storing related data.