{ "metadata": { "name": "", "signature": "sha256:e79a0eac03ad9579960d6637ee7084115a509425c890d49748b68f5c81462029" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Escape Sequences" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **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:**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Apostrophe" ] }, { "cell_type": "code", "collapsed": false, "input": [ "'Chris\\'s book'" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "\"Chris's book\"" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### New line" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print('Stay calm\\nand\\ncarry on')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Stay calm\n", "and\n", "carry on\n" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "For raw strings (i.e. you don't want Python to parse escape characters) place use r''" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Print exactly what is inside the quotation marks" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print(r'Chris\\'s book')" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Chris\\'s book\n" ] } ], "prompt_number": 6 } ], "metadata": {} } ] }