This is Field Calculator in ArcMap. I am trying to split the word after the first space if the words starts with "San" like San Francsico, San Diego and etc. It return an error. Below is the script.
As mentioned in the comments there are a few problems in your code, in order to address some of them try this:
def getSec(inField): if 'SAN' in inField.upper().split(' '): return inField.split(' ')[inField.upper().split(' ').index('SAN')+1] else: return '' # better for a shapefile to return an empty string
Whenever string comparing always use upper() or lower() as python is case sensitive, then once you've determined the target string exists use index() to find it and get the next element (or even better use ' '.join( [...index():]) to get the next word to the end of the string):
' '.join(Name.split(' ')[Name.upper().split(' ').index('SAN')+1:])
Which will split strings like
'North San Fran' to
'San Fran East' to