In this code snippet:
s = 'clcoding'
index = s.find('z')
print(index)
s = 'clcoding': This assigns the string 'clcoding' to the variable s.
s.find('z'): The .find() method is used to search for the first occurrence of the specified substring 'z' in the string s. If the substring is found, it returns the index (position) of its first occurrence. If the substring is not found, .find() returns -1.
Since 'z' is not in the string 'clcoding', s.find('z') will return -1.
print(index): This prints the value of index, which in this case is -1.
Output: -1
0 Comments:
Post a Comment