{ "metadata": { "name": "ex.6" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# \u4e60\u98986: \u5b57\u7b26\u4e32\u548c\u6587\u672c" ] }, { "cell_type": "code", "collapsed": false, "input": [ "x = \"There are %d types of people.\" % 10\n", "binary = \"binary\"\n", "do_not = \"don't\"\n", "y = \"Those who know %s and those who %s.\" % (binary, do_not)\n", "\n", "print x\n", "print y\n", "\n", "print \"I said: %r.\" % x\n", "print \"I also said: '%s'.\" % y\n", "\n", "hilarious = False\n", "joke_evaluation = \"Isn't that joke so funny?! %r\"\n", "\n", "print joke_evaluation % hilarious\n", "\n", "w = \"This is the left side of...\"\n", "e = \"a string with a right side.\"\n", "\n", "print w + e" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "There are 10 types of people.\n", "Those who know binary and those who don't.\n", "I said: 'There are 10 types of people.'.\n", "I also said: 'Those who know binary and those who don't.'.\n", "Isn't that joke so funny?! False\n", "This is the left side of...a string with a right side.\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "\u6ce8\u610f`%s`\u548c`%r`\u7684\u533a\u522b. r=raw, \u5373\u6570\u636e\u7684\u539f\u59cb\u5f62\u6001. \u5bf9\u4e8e\u5b57\u7b26\u4e32\u6765\u8bf4, \u5176\"\u539f\u59cb\"\u5f62\u6001\u5305\u542b\u5f15\u53f7." ] } ], "metadata": {} } ] }