|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Named parameters
I what to know how to create named parameters, like how they do in smalltalk. So ordering isn't required. Example person =method(age=”65”,name=”Gordon Brown”,sex=”male”) <-is the same as person =method(sex=”male”,name=”Gordon Brown”,age=”65”) <- this |
|
#2
|
||||
|
||||
|
You can do exactly that with any Python function/method call - just call the function with its parameter list like you did above.
|
|
#3
|
||||
|
||||
|
This example shows several ways of passing arguments to a function/methods; ordered and unordered:
Code:
>>> def foo(param1, param2, param3):
... print param1, param2, param3
...
>>> foo('one', 'two', 'three')
one two three
>>> foo(param1 = 'one', param3 = 'three', param2 = 'two')
one two three
>>> params = ('one', 'two', 'three')
>>> params
('one', 'two', 'three')
>>> foo(*params)
one two three
>>> params = {'param1': 'one', 'param3': 'three', 'param2': 'two'}
>>> params
{'param3': 'three', 'param2': 'two', 'param1': 'one'}
>>> foo(**params)
one two three
>>>
Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Smalltalk style named parameters |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|