imagine I type the following code into the interpreter:
var1 = 'zuuzuu'
now suppose i type:
var1.find('a')
the interpreter returns -1. which i understand because the substring has not been found. but please help me understand this:
var1.find('a' or 'z') #case 1
returns -1
but
var1.find('a' and 'z') #case 2
returns 0
According to the logic in my head the interpreter should return -1 for case 2 because the substrings ‘a’ AND ‘z’ are NOT located in the string. While in case 1, 0 should be returned since ‘z’ is a substring.
thanks
Expression
'a' or 'z'always yields'a'. Expression'a' and 'z'always yields'z'. It’s not some kind of DSL for making queries into containers, it’s a simple boolean expression (andfindis called with its result). If you want to say “is there ‘a’ or ‘z’ in the string”, you need to doAnd for the second one (both ‘a’ and ‘z’ in the string):