UTF-8 characters in doctest
J. Cliff Dyer
jcd at sdf.lonestar.org
Thu Sep 20 23:04:49 EDT 2007
John J. Lee wrote:
> Peter Otten <__peter__ at web.de> writes:
> [...]
>
>> def f(s):
>> return (s,)
>>
>
> Forgive me if this is a stupid question, but: What purpose does
> function f serve?
>
>
> John
>
Well, it has nothing to do with the unicode bit that came before it. It
just takes an argument, and wraps it in a 1-tuple. Guessing by the
argument of "s", that argument is expected to be a string.
One use I can think of is that sometimes you'll find a function that
returns a string or a list or tuple of strings. If you want to pass that
result on to a for loop, and only loop once on the string (instead of
looping on each letter of the string), you might want to wrap it in a
tuple or a list before passing it to the loop.
Cheers,
Cliff
More information about the Python-list
mailing list