Swap Variable
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: swap-variable
Section titled “Sourcery refactoring id: swap-variable”Description:
Section titled “Description:”Swap variable values with tuple assignment
Before:
Section titled “Before:”temp = aa = bb = tempAfter:
Section titled “After:”a, b = b, aExplanation:
Section titled “Explanation:”When trying to swap the values held by two variables, we may avoid using an extra temporary variable unnecessarily by employing Python’s tuple assignment. As a consequence of this refactoring, the code is not only more concise but also reflects its intention more clearly.