I'm having a bit of trouble understanding how this is happening. When I run the following:
def find_in_string(string, ch):
count = 0
index = 0
while 0 <= index < len(string):
if string.find(string, ch, index) != -1:
return True
find_in_string('asdfasdf', 's')
Here's what is I get:
TypeError: slice indices must be integers or None or have an __index__ method
However, running this through the interpreter like so:
index = 0
if string.find('asdfasdf', 's', index) != -1:
return True
It returns 'True'. So I'm not understanding how string.find isn't getting passed an integer for the starting index in the above function. Any advice appreciated!
EDIT: For whatever reason, the above function now works after importing string again. Perhaps too much coffee?
stringas a variable name. It's a commonly used module that comes with python.