Stackstack Stackstack - 1 year ago 75
Python Question

Find function in Python 3.x

When we have the following:

tweet2 = 'Want cheap snacks? Visit @cssu office in BA2283'

results in the output
and I cant wrap my head around how it does this. I tried the visualizer and it didn't show anything. Could anyone please explain?

Answer Source

tweet2.find('cheap') returns the index at which the beginning of "cheap" is found, and when that index is used in tweet2[index], it returns the character at that index, which is "c"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download