Learning Python: Chapter 16
Friday, 22 February 2008
- Declaring a variable in a function as global is only necessary for reassignments, not for mere read-access.
def foo(x, y, z): passfoo(10, 20, 30)
does the same as
params = [10, 20, 30]
foo(*params)def foo(x = 0, y = 0, z = 0): passfoo(x = 10, y = 20, z = 30)
does the same as
params = { 'x' : 10, 'y' : 20, 'z' : 30 }
foo(**params)
def foo(*params): passsets params to
foo(10, 20, 30)[10, 20, 30]def foo(**params): passsets params to
foo(x = 10, y = 20, z = 30){ 'x' : 10, 'y' : 20, 'z' : 30 }
| Perl | Python |
my $x = 10;
sub foo
{
$x = 20;
}
|
x = 10 def foo(): global x x = 20 |
I Am a Strange Loop
Seven Languages in Seven Weeks
A Short History of Nearly Everything