find(substring ,beginIndex, endIndex) — Python Technical Interview Questions & Answers
find(substring ,beginIndex, endIndex)
find(substring ,beginIndex, endIndex)
- find is a string helper. You call it on text like "Asha" or "banana". It gives a new string (or a number/True-False). The old string does not change unless you assign the result back.
- find(substring ,beginIndex, endIndex) — output: 1 then -1. Missing → -1, not error.
- Fresher trap: writing s.find() and expecting s to update. Strings are immutable. Write s = s.find(...) if you need the new value (when it returns a string).
Technical Interview Tip: Call find on one real word and say what prints.
Code Examples for find(substring ,beginIndex, endIndex)
Example
# find(substring ,beginIndex, endIndex)
print("Asha".find("s"))
print("Asha".find("z"))
find(substring ,beginIndex, endIndex) — output: 1 then -1. Missing → -1, not error.
How to Explain find(substring ,beginIndex, endIndex) to an Interviewer
Explain find(substring ,beginIndex, endIndex) as if you are teaching a junior — definition, then one tiny script.
find works on str. find usually returns a new string.
What does the example print, and why?
find(substring ,beginIndex, endIndex) — output: 1 then -1
What mistake do freshers make with find(substring ,beginIndex, endIndex)?
find does not change the original string in place.