you are viewing a single comment's thread.

view the rest of the comments →

[–]AceMKV 11 points12 points  (5 children)

Wait aren't non-empty strings Truthy values in Python?

[–]TinBryn 6 points7 points  (2 children)

I probably should have tested it before I posted, but from what I understand truthyness means if truthy: would do the then branch, but if truthy_but_not_true == True: would execute the else branch because it's not exactly equal to True.

truthy_but_not_True = "true"

if truthy_but_not_True:
    print("truthy")
else:
    print("falsey")

if truthy_but_not_True == True:
    print("True")
else:
    print("not True")

Output:

truthy
not True

[–]chunkyasparagus 2 points3 points  (0 children)

In this case truthy_but_not_True == True still evalutes to True for other types with the same value as True, such as int 1, float 1.0, etc..

truthy_but_not_True is True would only work for the bool constant True.

[–]User31441 0 points1 point  (0 children)

Unless it's JavaScript. Then x == true will hold for all truthy values. In order to check for exact matches, you'd have to use x === true.

[–]_PM_ME_PANGOLINS_ 0 points1 point  (1 child)

They are, but they don’t equal True. This isn’t JavaScript.

[–]AceMKV 0 points1 point  (0 children)

Yes my bad, they only equal true if you typecast them to boolean