[Tutor] problem with code

Alan Gauld alan.gauld at btinternet.com
Thu Aug 20 21:06:46 CEST 2015

On 20/08/15 18:07, Alan Gauld wrote:

>> (print("that seems reasonable")) if time<=2
>> else print ("get a life")

> There is an alternative way of writing what you want but
> it's not very commonly used:
> print("that seems reasonable" if time <=2 else "get a life")

I just realized that the OP's version would actually work
in Python v3 because print is a function.

It effectively evaluates as

None if time <= 2 else None

But can I suggest that it's not a good style to get into.
Either of the options that i suggested in my last mail
would be more idiomatic in the Python community.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list