Sunday, September 29, 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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...