![]() ![]() The and operator can combine as many conditions as needed. # If statement that requires several True conditions Multiple or statements python code#Since they are, that code executes and has print() display the following: Current temperature (30.2) is between high and low extremes. That makes our if statement only run when both are True. We combine those conditions with the and operator. The other looks if the temperature is under the record high ( currentTemp < tempHigh). # Current temperature currentTemp = 30.2 # Extremes in temperature (in Celsius) tempHigh = 40.7 tempLow = - 18.9 # Compare current temperature against extremes if currentTemp > tempLow and currentTemp tempLow). So when we combine conditions with and, both have to be True at the same time. # If statement that needs two True conditions Such a combined condition becomes False as soon as one condition tests False. When an if statement requires several True conditions at the same time, we join those different conditions together with the and operator. # Multiple True conditions in an if statement: the and operator Speaking of which, let’s take a look at those examples. The only time that or returns False is when both conditions are False too.ĭon’t worry if this sounds abstract or vague the examples below make this more practical.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |