Find function in Python 3.x
<p>When we have the following: </p>

<pre><code>tweet2 = 'Want cheap snacks? Visit @cssu office in BA2283'
</code></pre>

<p><code>print(tweet2[tweet2.find('cheap')])</code> results in the output <code>'c'</code> 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?</p>

<p>It's because the find(str, string) method determines if str occurs in string, or in a substring of string and returns the position of first occurrence. So when you call <code>tweet2.find('cheap')</code> it will return the <strong>position</strong> that is the first occurs of cheap.</p>

python python-3.x