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. How do you swap two variables in Python without a temporary variable?

    Use tuple unpacking: a, b = b, a. The right side is evaluated into a tuple first, then assigned to the names on the left, so no temporary variable is needed.

    BeginnerQuick answer1 min read