I'd like to know how the following string processing works for the text file given below. It tries to get what follows in lines starting with "name:..."
The part of the 4th line
line[len('name:'):]
does not seem very intuitive in helping me understand how it works.It seems like its getting the length of 'name:'. Also what is the extra : following ) for ?
for line in lines:
line=line.rstrip('\n') # assuming it came from a file, remove newline
if line.startswith('name:'):
print('The name is '+line[len('name:'):])
else:
print('The content is '+line)
It parses a text file with the following content
name:english
1001Nights
A Night at the Call Center
Grammar
name:science
Engineering
Biology
Physics
name:maths
Algebra
Geometry
Thanks in Advance for all your help