Sunday 29 September 2019

Using or in if statement (Python)

You can't use it like that. The or operator must have two boolean operands. You have a boolean and a string. You can write



weather == "Good!" or weather == "Great!": 


or



weather in ("Good!", "Great!"): 



Especially in the case of python, non empty strings evaluate to True, so



weather == "Good" or "Great":


will always be true, because "Great" is always true, making it a difficult mistake to spot.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...