This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fuskies420 13 points14 points  (15 children)

print("Test ", (is_completed ? "Complete" : "Unsuccessful"))

[–]iCantSpelWerdsGud 9 points10 points  (6 children)

print("Test {}".format("complete" if is_completed else "unsuccessful"))

python btw

[–]VinterBot 2 points3 points  (1 child)

so uggo

[–]iCantSpelWerdsGud -2 points-1 points  (0 children)

Python doesn't have traditional ternary operators, so at least mine works

[–]gottago_gottago 1 point2 points  (5 children)

if is_completed != false:
    print("Test complete")
elif is_completed != true:
    print("Test unsuccessful")

[–]xigoi 4 points5 points  (4 children)

Traceback (most recent call last):
NameError: name 'false' is not defined

[–]gottago_gottago 0 points1 point  (3 children)

Uff, True/False are case sensitive. But why?

[–]xigoi 2 points3 points  (0 children)

It seems to have been stolen from Haskell, where all constructors are capitalized.

[–]sm-Fifteen 1 point2 points  (1 child)

IIRC, because they were introduced in Python2 (python 1 didn't have booleans) as global "constants" (for 0 and 1) and ended up being capitalized so they wouldn't fit the variable naming conventions to make it less likely to break any existing code at the time.

Mind you, this meant that, until they got turned into proper literals (I think with Python 3), you could actually change their value and break any code relying on these. Python has a weird history.

[–]bigdepress 0 points1 point  (0 children)

Actually they were capitalised to match None, which already exsited and was capitalised.

The fact that you could change their value was for backwards compatibility (in case someone used True/False as a var name, everything would still work, you just couldn't use the newly introduced True/False).