It keeps printing 'found' although there is no 'jpg 'or 'jpeg' or 'png' or 'bmp' or 'gif' in 'asduas'. What am i doing wrong? :s
if 'jpg 'or 'jpeg' or 'png' or 'bmp' or 'gif' in 'asduas':
    print('found')
else:
    print('not found')
It keeps printing 'found' although there is no 'jpg 'or 'jpeg' or 'png' or 'bmp' or 'gif' in 'asduas'. What am i doing wrong? :s
if 'jpg 'or 'jpeg' or 'png' or 'bmp' or 'gif' in 'asduas':
    print('found')
else:
    print('not found')
 
    
    Another way:
if any(x in 'asudas' for x in ('jpg','jpeg','png','bmp','gif')):
    print('Found')
 
    
    The correct way to do this is for example:
if 'jpg' in 'asduas'  or 'jpeg' in 'asduas' or 'png' in 'asduas' or 'bmp' in 'asduas' or 'gif' in 'asduas':
    print('found')
 
    
    Your if evaluates if either of the following results in True:
'jpg'
'jpeg'
'png'
'bmp'
'gif' in 'asduas'
Because 'jpg' evaluates to True it wil enter the if always.
What you probably want
if any(x in 'asduas' for x in ('jpg', 'jpeg', 'png', 'bmp', 'gif')):
 
    
    You misunderstand how boolean expressions work. You are looking for:
if 'jpg' in 'asduas'  or 'jpeg' in 'asduas' or 'png' in 'asduas' or 'bmp' in 'asduas' or 'gif' in 'asduas':
    print('found')
else:
    print('not found')
You can even shorten it:
if any(x in 'asduas' for x in ('jpg','jpeg','png','bmp','gif')):
    print('found')
else:
    print('not found')
Because jpg gives True the if statement will always return true.