why i have the output of [None, None, None]
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Thu Apr 10 10:18:12 EDT 2014
length power writes:
> >>> x=['','x1','x2','x3',' ']
> >>> x
> ['', 'x1', 'x2', 'x3', ' ']
> >>> [print("ok") for it in x if it.strip() !=""]
> ok
> ok
> ok
> [None, None, None]
>
> i understand there are three 'ok' in the output,but why i have the
> output of [None, None, None]
It's a list containing the values from three invocations of print.
You get it because you asked for it.
|>>> print("ok") == None
|ok
|True
|>>> print("ok") != None
|ok
|False
|>>> [(print("ok") or "die") for x in (1,2,3)]
|ok
|ok
|ok
|['die', 'die', 'die']
|>>> [print("ok") for x in (1,2,3)] and print("What do you want it to be?")
|ok
|ok
|ok
|What do you want it to be?
|>>>
(That last one actually returns None to the interpreter, which
promptly does not print it.)
More information about the Python-list
mailing list