Interview Q&A / Python

INTERVIEW Q&A · 81 QUESTIONS

Python interview questions

Lists, dictionaries, generators, decorators and the Python questions asked in service-company and data roles.

  1. Why is "".join(list_of_strings) preferred over += inside a loop?

    Strings are immutable, so each += may copy the whole string built so far, which can become quadratic. join() computes the total size once and copies each piece a single time, so it runs in linear time.

    IntermediateQuick answer1 min read