COMP10001 Lecture 6: Week 6
![](https://new-preview-html.oneclass.com/1JRV4BM2KWx7j7bnrKLBmndkAG6LgqaP/bg1.png)
If mutable object is passed to a function and locally mutated, the change is preserved in the
global object
-
Functions and mutability:
Parameters = name that appear in a function definition
-
Arguments = values passed to a function when calling
-
Parameters can be given default arguments
-
Default arguments must follow non
-
default arguments
-
Arguments can be matched to parameters by position or by parameter names
-
Parameters and arguments:
Faster
-
Returning early:
A namespace is a mapping from names to objects
-
Global namespace in Python
-
Local namespace is called when function is called and forgotten after the function ends
-
Scope is the area of Python code where a particular namespace is used
-
Python first looks in the local namespace, then enclosing function namespaces and then in the
global namespace
-
Namespaces
Week 6
Sunday, 15 April 2018 6:42 PM
Foundations of Computing Page 1
Document Summary
If mutable object is passed to a function and locally mutated, the change is preserved in the global object. Parameters = name that appear in a function definition. Arguments = values passed to a function when calling. Arguments can be matched to parameters by position or by parameter names. A namespace is a mapping from names to objects. Local namespace is called when function is called and forgotten after the function ends. Scope is the area of python code where a particular namespace is used. Python first looks in the local namespace, then enclosing function namespaces and then in the global namespace.