translate(table,deletechars = '') — Python Technical Interview Questions & Answers

translate(table,deletechars = '')

translate(table,deletechars = '')

  • translate 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.
  • translate(table,deletechars = '') — output: Ash1. a→1, e→2 (none here).
  • Fresher trap: writing s.translate() and expecting s to update. Strings are immutable. Write s = s.translate(...) if you need the new value (when it returns a string).

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

Code Examples for translate(table,deletechars = '')

Example

# translate(table,deletechars = '')
t = str.maketrans("ae", "12")
print("Asha".translate(t))

translate(table,deletechars = '') — output: Ash1. a→1, e→2 (none here).

How to Explain translate(table,deletechars = '') to an Interviewer

Explain translate(table,deletechars = '') as if you are teaching a junior — definition, then one tiny script.

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

What does the example print, and why?

translate(table,deletechars = '') — output: Ash1

What mistake do freshers make with translate(table,deletechars = '')?

translate does not change the original string in place.