I am having trouble in parsing my string. Here are my codes:
name='report 11 hits'
print(name[7:9])
print(name[11:])
output:
11
hits
But, if I need to type the string as
name='report 112 hits'
print(name[7:9])
print(name[10:])
output:
11
hits
That means, whenever I am typing a number more than three digits, the program is not reading it well. I was wondering if someone could write me how to modify my code in such a way that no matter what digit I write, the program will read it correctly. Thanks.
You can use
split()and then print the second element of the generated list: