endswith(suffix ,begin=0,end=len(string)) — Python Technical Interview Questions & Answers

endswith(suffix ,begin=0,end=len(string))

endswith(suffix ,begin=0,end=len(string))

  • endswith 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.
  • endswith(suffix ,begin=0,end=len(string)) — output: True.
  • Fresher trap: writing s.endswith() and expecting s to update. Strings are immutable. Write s = s.endswith(...) if you need the new value (when it returns a string).

Technical Interview Tip: Call endswith on one real word and say what prints.

Code Examples for endswith(suffix ,begin=0,end=len(string))

Example

# endswith(suffix ,begin=0,end=len(string))
print("Asha.py".endswith(".py"))

endswith(suffix ,begin=0,end=len(string)) — output: True.

How to Explain endswith(suffix ,begin=0,end=len(string)) to an Interviewer

Explain endswith(suffix ,begin=0,end=len(string)) as if you are teaching a junior — definition, then one tiny script.

endswith works on str. endswith usually returns a new string.

What does the example print, and why?

endswith(suffix ,begin=0,end=len(string)) — output: True

What mistake do freshers make with endswith(suffix ,begin=0,end=len(string))?

endswith does not change the original string in place.