Why return None?

Ayose ayose.cazorla at hispalinux.es
Wed Aug 25 17:12:07 CEST 2004


[Martin DeMello]
> It seems to be a fairly common pattern for an object-modifying method to
> return None - however, this is often quite inconvenient.
> 
> For instance
> 
> def f(lst1, lst2):
>   g((lst1 + lst2).reverse()) # doesn't work!

If you can use python 2.3 or newer, try with [::-1]

    >>> def f(m, n):
    ...     print (m + n)[::-1]
    ... 
    >>> f([1,2,3], [10,20,30])
    [30, 20, 10, 3, 2, 1]
    >>> 




-- 
Ayose Cazorla León
Debian GNU/Linux - setepo



More information about the Python-list mailing list