Python Strings — Python Technical Interview Questions & Answers

Python Strings

Python Strings

  • A string is text — an ordered row of characters. "Asha" or 'Asha'. Multi-line with triple quotes. Index from 0: s[0] is A. s[-1] is the last letter. Slice s[1:3] is sh. Concatenate with +. Repeat with *. "sh" in "Asha" is True.
  • Strings cannot change in place. s[0] = "B" → TypeError. Methods return a new string. f"Hi {name}" inserts values. That immutability word is what interviews want. Then one slice and one f-string.
  • Python Strings — output: A, Ash, Hi Asha. Slice end is exclusive. String itself did not change.

Technical Interview Tip: Immutability + slice + f-string.

Code Examples for Python Strings

Example

# Strings
name = "Asha"
print(name[0])
print(name[0:3])
print(f"Hi {name}")

Python Strings — output: A, Ash, Hi Asha. Slice end is exclusive. String itself did not change.

How to Explain Python Strings to an Interviewer

Explain Strings as if you are teaching a junior — definition, then one tiny script.

Text sequence. Immutable. Index / slice. f-strings.

What does the example print, and why?

Python Strings — output: A, Ash, Hi Asha

What mistake do freshers make with Strings?

s[0] = "H" → TypeError.