[python] Simple 'if' or logic statement in Python

How would you write the following in Python?

if key < 1 or key > 34:

I've tried every way I can think of and am finding it very frustrating.

This question is related to python if-statement logic

The answer is


Here's a Boolean thing:

if (not suffix == "flac" )  or (not suffix == "cue" ):   # WRONG! FAILS
    print  filename + ' is not a flac or cue file'

but

if not (suffix == "flac"  or suffix == "cue" ):     # CORRECT!
       print  filename + ' is not a flac or cue file'

(not a) or (not b) == not ( a and b ) , is false only if a and b are both true

not (a or b) is true only if a and be are both false.


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to if-statement

How to use *ngIf else? SQL Server IF EXISTS THEN 1 ELSE 2 What is a good practice to check if an environmental variable exists or not? Using OR operator in a jquery if statement R multiple conditions in if statement Syntax for an If statement using a boolean How to have multiple conditions for one if statement in python Ifelse statement in R with multiple conditions If strings starts with in PowerShell Multiple conditions in an IF statement in Excel VBA

Examples related to logic

How to do perspective fixing? What is the optimal algorithm for the game 2048? ReferenceError: Invalid left-hand side in assignment Prolog "or" operator, query Write code to convert given number into words (eg 1234 as input should output one thousand two hundred and thirty four) JQuery .hasClass for multiple values in an if statement AND/OR in Python? Simple 'if' or logic statement in Python 1 = false and 0 = true? Reference — What does this symbol mean in PHP?