I understand using 0 and 1 for true and false evaluation, but can someone please explain the use of -1 to me in the following. s is a file name string.
if s.find(".py")==-1:
return False
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
s.find()method returns the index of the given substring ins. It is a number between0andlen(str) - 1in case the substring was found. In case it was not found,-1was chosen as return value because it does not collide with any valid return value for the case that it was found.Note that this line would be better written as
or — with a slightly different but probably intended meaning — as