{ "metadata": { "name": "", "signature": "sha256:8dba368923e2337ca50ee4b70cf67c6e4bce7b9895e378155706113fb8e1a86b" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Swapping variable values\n", "\n", "- **Author:** [Chris Albon](http://www.chrisalbon.com/), [@ChrisAlbon](https://twitter.com/chrisalbon)\n", "- **Date:** -\n", "- **Repo:** [Python 3 code snippets for data science](https://github.com/chrisalbon/code_py)\n", "- **Note:** Originally from: Learning Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setup the originally variables and their values" ] }, { "cell_type": "code", "collapsed": false, "input": [ "one = 1\n", "two = 2" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### View the original variables" ] }, { "cell_type": "code", "collapsed": false, "input": [ "'one =', one, 'two =', two" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 12, "text": [ "('one =', 1, 'two =', 2)" ] } ], "prompt_number": 12 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Swap the values" ] }, { "cell_type": "code", "collapsed": false, "input": [ "one, two = two, one" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### View the swapped values, notice how the values for each variable have changed" ] }, { "cell_type": "code", "collapsed": false, "input": [ "'one =', one, 'two =', two" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 14, "text": [ "('one =', 2, 'two =', 1)" ] } ], "prompt_number": 14 } ], "metadata": {} } ] }