I need a Python function that swaps the contents of two variables given by their references (exactly as std::swap in C++). How do I implement it or is there a standard built-in one? def my_swap(obj1, obj2): # What is here? # ... a = [1, 2, 3] b = {'x': 25} my_swap(a, b) print(a) # {'x': 25} This should work with arbitrary data types, even mixed ones. This question is not about swapping with temporary variable or understanding the difference between value and reference like in the questions: When is a variable passed by reference and when by value? Passing values in Python Continue reading...