Bitten by my C/Java experience
Andrew Cooper
amc96 at cam.ac.uk
Mon May 4 16:57:09 EDT 2015
On 04/05/2015 18:43, Ian Kelly wrote:
>
> Some other gotchas that aren't necessarily related to C/Java but can
> be surprising nonetheless:
>
> * () is a zero-element tuple, and (a, b) is a two-element tuple,
> but (a) is not a one-element tuple. Tuples are created by commas, not
> parentheses, so use (a,) instead.
* {} is an empty set(), not dict().
Particularly subtle when combined with **kwargs
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(**kwargs):
... return { (k, kwargs[k]) for k in kwargs }
...
>>> foo()
set()
>>> foo(a=1)
{('a', 1)}
>>>
~Andrew
More information about the Python-list
mailing list