Question
Complete the Python function to find the starting index of the first occurrence of sub in main_string. Return -1 if not found. def find_substring_index(main_string, sub): Â Â _________ # Line to complete
Solution
Correct Answer: A (str.find() returns -1 if not found, str.index() raises a ValueError.)
More IT Operating System Questions
- Which probability distribution is most widely used to model quantization noise in pulse code modulation ?
- Which algorithm is commonly used for Part-of-Speech tagging?
- CDATA is used in XML to:
- Consider the following Java code: class Animal { Â Â String type = "Generic Animal"; Â Â void eat() { Â Â Â Â System.out.println("Animal eats food."); ...
- In a Breadth-First Search (BFS) algorithm for graph traversal, what is the primary role of a queue?
- Complete a simple hash function for a string s that sums the ASCII values of its characters and then takes the modulo of a prime number M. def simple_ha...
- A C function print_matrix(int rows, int cols, int matrix[rows][cols]) is designed to print a matrix. #include void print_matrix(int rows, int cols, ...
- Which is used for C shell?
- Which keyword is used for inheritance in C++?
- Which Hadoop component is responsible for resource management?