{ "metadata": { "name": "ex.8" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# \u4e60\u98988: \u6253\u5370\uff0c\u6253\u5370" ] }, { "cell_type": "code", "collapsed": false, "input": [ "formatter = \"%r %r %r %r\"\n", "\n", "print formatter % (1, 2, 3, 4)\n", "print formatter % (\"one\", \"two\", \"three\", \"four\")\n", "print formatter % (True, False, False, True)\n", "print formatter % (formatter, formatter, formatter, formatter)\n", "print formatter % (\n", " \"I had this thing.\",\n", " \"That you could type up right.\",\n", " \"But it didn't sing.\",\n", " \"So I said goodnight.\"\n", ")" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1 2 3 4\n", "'one' 'two' 'three' 'four'\n", "True False False True\n", "'%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r'\n", "'I had this thing.' 'That you could type up right.' \"But it didn't sing.\" 'So I said goodnight.'\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "`%r`\u8f93\u51fa\u6570\u636e\u7684\u539f\u59cb\u8868\u793a, \u6bd4\u5982:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print '%r' % '\u840c'\n", "print '%s' % '\u840c'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "'\\xe8\\x90\\x8c'\n", "\u840c\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "print '\\xe8\\x90\\x8c'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\u840c\n" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "\u6570\u636e\u7684\u539f\u59cb\u8868\u793a\u5e76\u4e0d\u552f\u4e00, \u6bd4\u5982`'moe'`\u548c`\"moe\"`, `'\u840c'`\u548c`'\\xe8\\x90\\x8c'`." ] } ], "metadata": {} } ] }