String Intreview Question-Python
1. How would you confirm that 2 strings have the same identity? In [12]: animals = [ 'python' , 'gopher' ] more_animals = animals if id ( animals ) == id ( more_animals ): print ( "True" ) else : print ( "false" ) True 2. How would you check if each word in a string begins with a capital letter? In [13]: a = "Missile City Baleswar" print ( a . istitle ()) True 3. Check if a string contains a specific substring In [14]: a = "Missile City Baleswar" print ( 'Missile' in a ) True 4. Find the index of the first occurrence of a substring in a string In [15]: 'The worlds fastest plane' . find ( 'plane' ) #=> 19 Out[15]: 19 In [22]: ''' There are 2 different functions that will return the starting index, find() and index(). They have slightly different behaviour. find() returns -1 if the substring is not found.''' a = "Missile City Bale...