Skip to content

Instantly share code, notes, and snippets.

@coder-shanks
Created March 19, 2019 11:35
Show Gist options
  • Save coder-shanks/2432dc5026d9d17afddfd5415b0fc75d to your computer and use it in GitHub Desktop.
Save coder-shanks/2432dc5026d9d17afddfd5415b0fc75d to your computer and use it in GitHub Desktop.
Swap the two numbers using a third variable
first_number = 5
second_number = 7
# Storing the value of first number in a temporary variable
temp = first_number # temp = 5
# Replacing the value of first_number by second_number
first_number = second_number # first_number = 7
# Assigning the cached value of first number in temp variable
# to second_number
second_number = temp # second_number = 5
@coder-shanks
Copy link
Author

Swap the two numbers using a third variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment