home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pytexdoc / ext / lib / tut / tex
LaTeX Document  |  1996-11-08  |  149.3 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
99% dexvert Texinfo Document (document/texInfo) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file TeX document text default
98% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 64 6f 63 75 6d 65 6e | 74 73 74 79 6c 65 5b 74 |\documen|tstyle[t|
|00000010| 77 6f 73 69 64 65 2c 31 | 31 70 74 2c 6d 79 66 6f |woside,1|1pt,myfo|
|00000020| 72 6d 61 74 5d 7b 72 65 | 70 6f 72 74 7d 0a 0a 5c |rmat]{re|port}..\|
|00000030| 74 69 74 6c 65 7b 50 79 | 74 68 6f 6e 20 54 75 74 |title{Py|thon Tut|
|00000040| 6f 72 69 61 6c 7d 0a 0a | 5c 69 6e 70 75 74 7b 62 |orial}..|\input{b|
|00000050| 6f 69 6c 65 72 70 6c 61 | 74 65 7d 0a 0a 5c 62 65 |oilerpla|te}..\be|
|00000060| 67 69 6e 7b 64 6f 63 75 | 6d 65 6e 74 7d 0a 0a 5c |gin{docu|ment}..\|
|00000070| 70 61 67 65 6e 75 6d 62 | 65 72 69 6e 67 7b 72 6f |pagenumb|ering{ro|
|00000080| 6d 61 6e 7d 0a 0a 5c 6d | 61 6b 65 74 69 74 6c 65 |man}..\m|aketitle|
|00000090| 0a 0a 5c 69 6e 70 75 74 | 7b 63 6f 70 79 72 69 67 |..\input|{copyrig|
|000000a0| 68 74 7d 0a 0a 5c 62 65 | 67 69 6e 7b 61 62 73 74 |ht}..\be|gin{abst|
|000000b0| 72 61 63 74 7d 0a 0a 5c | 6e 6f 69 6e 64 65 6e 74 |ract}..\|noindent|
|000000c0| 0a 50 79 74 68 6f 6e 20 | 69 73 20 61 20 73 69 6d |.Python |is a sim|
|000000d0| 70 6c 65 2c 20 79 65 74 | 20 70 6f 77 65 72 66 75 |ple, yet| powerfu|
|000000e0| 6c 20 70 72 6f 67 72 61 | 6d 6d 69 6e 67 20 6c 61 |l progra|mming la|
|000000f0| 6e 67 75 61 67 65 20 74 | 68 61 74 20 62 72 69 64 |nguage t|hat brid|
|00000100| 67 65 73 20 74 68 65 0a | 67 61 70 20 62 65 74 77 |ges the.|gap betw|
|00000110| 65 65 6e 20 43 20 61 6e | 64 20 73 68 65 6c 6c 20 |een C an|d shell |
|00000120| 70 72 6f 67 72 61 6d 6d | 69 6e 67 2c 20 61 6e 64 |programm|ing, and|
|00000130| 20 69 73 20 74 68 75 73 | 20 69 64 65 61 6c 6c 79 | is thus| ideally|
|00000140| 20 73 75 69 74 65 64 20 | 66 6f 72 0a 60 60 74 68 | suited |for.``th|
|00000150| 72 6f 77 2d 61 77 61 79 | 20 70 72 6f 67 72 61 6d |row-away| program|
|00000160| 6d 69 6e 67 27 27 0a 61 | 6e 64 20 72 61 70 69 64 |ming''.a|nd rapid|
|00000170| 20 70 72 6f 74 6f 74 79 | 70 69 6e 67 2e 20 20 49 | prototy|ping. I|
|00000180| 74 73 20 73 79 6e 74 61 | 78 20 69 73 20 70 75 74 |ts synta|x is put|
|00000190| 0a 74 6f 67 65 74 68 65 | 72 20 66 72 6f 6d 20 63 |.togethe|r from c|
|000001a0| 6f 6e 73 74 72 75 63 74 | 73 20 62 6f 72 72 6f 77 |onstruct|s borrow|
|000001b0| 65 64 20 66 72 6f 6d 20 | 61 20 76 61 72 69 65 74 |ed from |a variet|
|000001c0| 79 20 6f 66 20 6f 74 68 | 65 72 20 6c 61 6e 67 75 |y of oth|er langu|
|000001d0| 61 67 65 73 3b 0a 6d 6f | 73 74 20 70 72 6f 6d 69 |ages;.mo|st promi|
|000001e0| 6e 65 6e 74 20 61 72 65 | 20 69 6e 66 6c 75 65 6e |nent are| influen|
|000001f0| 63 65 73 20 66 72 6f 6d | 20 41 42 43 2c 20 43 2c |ces from| ABC, C,|
|00000200| 20 4d 6f 64 75 6c 61 2d | 33 20 61 6e 64 20 49 63 | Modula-|3 and Ic|
|00000210| 6f 6e 2e 0a 0a 54 68 65 | 20 50 79 74 68 6f 6e 20 |on...The| Python |
|00000220| 69 6e 74 65 72 70 72 65 | 74 65 72 20 69 73 20 65 |interpre|ter is e|
|00000230| 61 73 69 6c 79 20 65 78 | 74 65 6e 64 65 64 20 77 |asily ex|tended w|
|00000240| 69 74 68 20 6e 65 77 20 | 66 75 6e 63 74 69 6f 6e |ith new |function|
|00000250| 73 20 61 6e 64 20 64 61 | 74 61 0a 74 79 70 65 73 |s and da|ta.types|
|00000260| 20 69 6d 70 6c 65 6d 65 | 6e 74 65 64 20 69 6e 20 | impleme|nted in |
|00000270| 43 2e 20 20 50 79 74 68 | 6f 6e 20 69 73 20 61 6c |C. Pyth|on is al|
|00000280| 73 6f 20 73 75 69 74 61 | 62 6c 65 20 61 73 20 61 |so suita|ble as a|
|00000290| 6e 20 65 78 74 65 6e 73 | 69 6f 6e 0a 6c 61 6e 67 |n extens|ion.lang|
|000002a0| 75 61 67 65 20 66 6f 72 | 20 68 69 67 68 6c 79 20 |uage for| highly |
|000002b0| 63 75 73 74 6f 6d 69 7a | 61 62 6c 65 20 43 20 61 |customiz|able C a|
|000002c0| 70 70 6c 69 63 61 74 69 | 6f 6e 73 20 73 75 63 68 |pplicati|ons such|
|000002d0| 20 61 73 20 65 64 69 74 | 6f 72 73 20 6f 72 0a 77 | as edit|ors or.w|
|000002e0| 69 6e 64 6f 77 20 6d 61 | 6e 61 67 65 72 73 2e 0a |indow ma|nagers..|
|000002f0| 0a 50 79 74 68 6f 6e 20 | 69 73 20 61 76 61 69 6c |.Python |is avail|
|00000300| 61 62 6c 65 20 66 6f 72 | 20 76 61 72 69 6f 75 73 |able for| various|
|00000310| 20 6f 70 65 72 61 74 69 | 6e 67 20 73 79 73 74 65 | operati|ng syste|
|00000320| 6d 73 2c 20 61 6d 6f 6e | 67 73 74 20 77 68 69 63 |ms, amon|gst whic|
|00000330| 68 0a 73 65 76 65 72 61 | 6c 20 66 6c 61 76 6f 72 |h.severa|l flavor|
|00000340| 73 20 6f 66 20 7b 5c 55 | 4e 49 58 7d 2c 20 74 68 |s of {\U|NIX}, th|
|00000350| 65 20 41 70 70 6c 65 20 | 4d 61 63 69 6e 74 6f 73 |e Apple |Macintos|
|00000360| 68 2c 20 4d 53 2d 44 4f | 53 2c 20 57 69 6e 64 6f |h, MS-DO|S, Windo|
|00000370| 77 73 0a 28 33 2e 31 28 | 31 29 2c 20 27 39 35 20 |ws.(3.1(|1), '95 |
|00000380| 61 6e 64 20 4e 54 20 66 | 6c 61 76 6f 72 73 29 2c |and NT f|lavors),|
|00000390| 20 4f 53 2f 32 2c 20 61 | 6e 64 20 6f 74 68 65 72 | OS/2, a|nd other|
|000003a0| 73 2e 0a 0a 54 68 69 73 | 20 74 75 74 6f 72 69 61 |s...This| tutoria|
|000003b0| 6c 20 69 6e 74 72 6f 64 | 75 63 65 73 20 74 68 65 |l introd|uces the|
|000003c0| 20 72 65 61 64 65 72 20 | 69 6e 66 6f 72 6d 61 6c | reader |informal|
|000003d0| 6c 79 20 74 6f 20 74 68 | 65 20 62 61 73 69 63 20 |ly to th|e basic |
|000003e0| 63 6f 6e 63 65 70 74 73 | 0a 61 6e 64 20 66 65 61 |concepts|.and fea|
|000003f0| 74 75 72 65 73 20 6f 66 | 20 74 68 65 20 50 79 74 |tures of| the Pyt|
|00000400| 68 6f 6e 20 6c 61 6e 67 | 75 61 67 65 20 61 6e 64 |hon lang|uage and|
|00000410| 20 73 79 73 74 65 6d 2e | 20 20 49 74 20 68 65 6c | system.| It hel|
|00000420| 70 73 20 74 6f 20 68 61 | 76 65 20 61 0a 50 79 74 |ps to ha|ve a.Pyt|
|00000430| 68 6f 6e 20 69 6e 74 65 | 72 70 72 65 74 65 72 20 |hon inte|rpreter |
|00000440| 68 61 6e 64 79 20 66 6f | 72 20 68 61 6e 64 73 2d |handy fo|r hands-|
|00000450| 6f 6e 20 65 78 70 65 72 | 69 65 6e 63 65 2c 20 62 |on exper|ience, b|
|00000460| 75 74 20 61 73 20 74 68 | 65 20 65 78 61 6d 70 6c |ut as th|e exampl|
|00000470| 65 73 0a 61 72 65 20 73 | 65 6c 66 2d 63 6f 6e 74 |es.are s|elf-cont|
|00000480| 61 69 6e 65 64 2c 20 74 | 68 65 20 74 75 74 6f 72 |ained, t|he tutor|
|00000490| 69 61 6c 20 63 61 6e 20 | 62 65 20 72 65 61 64 20 |ial can |be read |
|000004a0| 6f 66 66 2d 6c 69 6e 65 | 20 61 73 20 77 65 6c 6c |off-line| as well|
|000004b0| 2e 0a 0a 46 6f 72 20 61 | 20 64 65 73 63 72 69 70 |...For a| descrip|
|000004c0| 74 69 6f 6e 20 6f 66 20 | 73 74 61 6e 64 61 72 64 |tion of |standard|
|000004d0| 20 6f 62 6a 65 63 74 73 | 20 61 6e 64 20 6d 6f 64 | objects| and mod|
|000004e0| 75 6c 65 73 2c 20 73 65 | 65 20 74 68 65 20 7b 5c |ules, se|e the {\|
|000004f0| 65 6d 20 50 79 74 68 6f | 6e 0a 4c 69 62 72 61 72 |em Pytho|n.Librar|
|00000500| 79 20 52 65 66 65 72 65 | 6e 63 65 7d 20 64 6f 63 |y Refere|nce} doc|
|00000510| 75 6d 65 6e 74 2e 20 20 | 54 68 65 20 7b 5c 65 6d |ument. |The {\em|
|00000520| 20 50 79 74 68 6f 6e 20 | 52 65 66 65 72 65 6e 63 | Python |Referenc|
|00000530| 65 20 4d 61 6e 75 61 6c | 7d 20 67 69 76 65 73 0a |e Manual|} gives.|
|00000540| 61 20 6d 6f 72 65 20 66 | 6f 72 6d 61 6c 20 64 65 |a more f|ormal de|
|00000550| 66 69 6e 69 74 69 6f 6e | 20 6f 66 20 74 68 65 20 |finition| of the |
|00000560| 6c 61 6e 67 75 61 67 65 | 2e 0a 0a 5c 65 6e 64 7b |language|...\end{|
|00000570| 61 62 73 74 72 61 63 74 | 7d 0a 0a 5c 70 61 67 65 |abstract|}..\page|
|00000580| 62 72 65 61 6b 0a 7b 0a | 5c 70 61 72 73 6b 69 70 |break.{.|\parskip|
|00000590| 20 3d 20 30 6d 6d 0a 5c | 74 61 62 6c 65 6f 66 63 | = 0mm.\|tableofc|
|000005a0| 6f 6e 74 65 6e 74 73 0a | 7d 0a 0a 5c 70 61 67 65 |ontents.|}..\page|
|000005b0| 62 72 65 61 6b 0a 0a 5c | 70 61 67 65 6e 75 6d 62 |break..\|pagenumb|
|000005c0| 65 72 69 6e 67 7b 61 72 | 61 62 69 63 7d 0a 0a 0a |ering{ar|abic}...|
|000005d0| 5c 63 68 61 70 74 65 72 | 7b 57 68 65 74 74 69 6e |\chapter|{Whettin|
|000005e0| 67 20 59 6f 75 72 20 41 | 70 70 65 74 69 74 65 7d |g Your A|ppetite}|
|000005f0| 0a 0a 5c 73 65 63 74 69 | 6f 6e 7b 44 69 73 63 6c |..\secti|on{Discl|
|00000600| 61 69 6d 65 72 7d 0a 0a | 4e 6f 77 20 74 68 61 74 |aimer}..|Now that|
|00000610| 20 74 68 65 72 65 20 61 | 72 65 20 73 65 76 65 72 | there a|re sever|
|00000620| 61 6c 20 62 6f 6f 6b 73 | 20 6f 75 74 20 6f 6e 20 |al books| out on |
|00000630| 50 79 74 68 6f 6e 2c 20 | 74 68 69 73 20 74 75 74 |Python, |this tut|
|00000640| 6f 72 69 61 6c 20 68 61 | 73 20 6c 6f 73 74 0a 69 |orial ha|s lost.i|
|00000650| 74 73 20 72 6f 6c 65 20 | 61 73 20 74 68 65 20 6f |ts role |as the o|
|00000660| 6e 6c 79 20 69 6e 74 72 | 6f 64 75 63 74 69 6f 6e |nly intr|oduction|
|00000670| 20 74 6f 20 50 79 74 68 | 6f 6e 20 66 6f 72 20 6d | to Pyth|on for m|
|00000680| 6f 73 74 20 6e 65 77 20 | 75 73 65 72 73 2e 20 20 |ost new |users. |
|00000690| 49 74 0a 74 61 6b 65 73 | 20 74 69 6d 65 20 74 6f |It.takes| time to|
|000006a0| 20 6b 65 65 70 20 61 20 | 64 6f 63 75 6d 65 6e 74 | keep a |document|
|000006b0| 20 6c 69 6b 65 20 74 68 | 69 73 20 75 70 20 74 6f | like th|is up to|
|000006c0| 20 64 61 74 65 20 69 6e | 20 74 68 65 20 66 61 63 | date in| the fac|
|000006d0| 65 20 6f 66 0a 61 64 64 | 69 74 69 6f 6e 73 20 74 |e of.add|itions t|
|000006e0| 6f 20 74 68 65 20 6c 61 | 6e 67 75 61 67 65 2c 20 |o the la|nguage, |
|000006f0| 61 6e 64 20 49 20 73 69 | 6d 70 6c 79 20 64 6f 6e |and I si|mply don|
|00000700| 27 74 20 68 61 76 65 20 | 65 6e 6f 75 67 68 20 74 |'t have |enough t|
|00000710| 69 6d 65 20 74 6f 20 64 | 6f 20 61 0a 67 6f 6f 64 |ime to d|o a.good|
|00000720| 20 6a 6f 62 2e 20 20 54 | 68 65 72 65 66 6f 72 65 | job. T|herefore|
|00000730| 2c 20 74 68 69 73 20 76 | 65 72 73 69 6f 6e 20 6f |, this v|ersion o|
|00000740| 66 20 74 68 65 20 74 75 | 74 6f 72 69 61 6c 20 69 |f the tu|torial i|
|00000750| 73 20 61 6c 6d 6f 73 74 | 20 75 6e 63 68 61 6e 67 |s almost| unchang|
|00000760| 65 64 0a 73 69 6e 63 65 | 20 74 68 65 20 70 72 65 |ed.since| the pre|
|00000770| 76 69 6f 75 73 20 72 65 | 6c 65 61 73 65 2e 20 20 |vious re|lease. |
|00000780| 54 68 69 73 20 64 6f 65 | 73 6e 27 74 20 6d 65 61 |This doe|sn't mea|
|00000790| 6e 20 74 68 61 74 20 74 | 68 65 20 74 75 74 6f 72 |n that t|he tutor|
|000007a0| 69 61 6c 20 69 73 0a 6f | 75 74 20 6f 66 20 64 61 |ial is.o|ut of da|
|000007b0| 74 65 20 2d 2d 2d 20 61 | 6c 6c 20 74 68 65 20 65 |te --- a|ll the e|
|000007c0| 78 61 6d 70 6c 65 73 20 | 73 74 69 6c 6c 20 77 6f |xamples |still wo|
|000007d0| 72 6b 20 65 78 61 63 74 | 6c 79 20 61 73 20 62 65 |rk exact|ly as be|
|000007e0| 66 6f 72 65 2e 20 20 54 | 68 65 72 65 0a 61 72 65 |fore. T|here.are|
|000007f0| 20 73 69 6d 70 6c 79 20 | 73 6f 6d 65 20 6e 65 77 | simply |some new|
|00000800| 20 61 72 65 61 73 20 6f | 66 20 74 68 65 20 6c 61 | areas o|f the la|
|00000810| 6e 67 75 61 67 65 20 74 | 68 61 74 20 61 72 65 6e |nguage t|hat aren|
|00000820| 27 74 20 63 6f 76 65 72 | 65 64 2e 0a 0a 54 6f 20 |'t cover|ed...To |
|00000830| 6d 61 6b 65 20 75 70 20 | 66 6f 72 20 74 68 69 73 |make up |for this|
|00000840| 2c 20 74 68 65 72 65 20 | 61 72 65 20 73 6f 6d 65 |, there |are some|
|00000850| 20 63 68 61 70 74 65 72 | 73 20 61 74 20 74 68 65 | chapter|s at the|
|00000860| 20 65 6e 64 20 63 6f 76 | 65 72 0a 69 6d 70 6f 72 | end cov|er.impor|
|00000870| 74 61 6e 74 20 63 68 61 | 6e 67 65 73 20 69 6e 20 |tant cha|nges in |
|00000880| 72 65 63 65 6e 74 20 50 | 79 74 68 6f 6e 20 72 65 |recent P|ython re|
|00000890| 6c 65 61 73 65 73 2c 20 | 61 6e 64 20 74 68 65 73 |leases, |and thes|
|000008a0| 65 20 61 72 65 20 75 70 | 20 74 6f 20 64 61 74 65 |e are up| to date|
|000008b0| 0a 77 69 74 68 20 74 68 | 65 20 63 75 72 72 65 6e |.with th|e curren|
|000008c0| 74 20 72 65 6c 65 61 73 | 65 2e 0a 0a 5c 73 65 63 |t releas|e...\sec|
|000008d0| 74 69 6f 6e 7b 49 6e 74 | 72 6f 64 75 63 74 69 6f |tion{Int|roductio|
|000008e0| 6e 7d 0a 0a 49 66 20 79 | 6f 75 20 65 76 65 72 20 |n}..If y|ou ever |
|000008f0| 77 72 6f 74 65 20 61 20 | 6c 61 72 67 65 20 73 68 |wrote a |large sh|
|00000900| 65 6c 6c 20 73 63 72 69 | 70 74 2c 20 79 6f 75 20 |ell scri|pt, you |
|00000910| 70 72 6f 62 61 62 6c 79 | 20 6b 6e 6f 77 20 74 68 |probably| know th|
|00000920| 69 73 0a 66 65 65 6c 69 | 6e 67 3a 20 79 6f 75 27 |is.feeli|ng: you'|
|00000930| 64 20 6c 6f 76 65 20 74 | 6f 20 61 64 64 20 79 65 |d love t|o add ye|
|00000940| 74 20 61 6e 6f 74 68 65 | 72 20 66 65 61 74 75 72 |t anothe|r featur|
|00000950| 65 2c 20 62 75 74 20 69 | 74 27 73 20 61 6c 72 65 |e, but i|t's alre|
|00000960| 61 64 79 20 73 6f 0a 73 | 6c 6f 77 2c 20 61 6e 64 |ady so.s|low, and|
|00000970| 20 73 6f 20 62 69 67 2c | 20 61 6e 64 20 73 6f 20 | so big,| and so |
|00000980| 63 6f 6d 70 6c 69 63 61 | 74 65 64 3b 20 6f 72 20 |complica|ted; or |
|00000990| 74 68 65 20 66 65 61 74 | 75 72 65 20 69 6e 76 6f |the feat|ure invo|
|000009a0| 6c 76 65 73 20 61 20 73 | 79 73 74 65 6d 0a 63 61 |lves a s|ystem.ca|
|000009b0| 6c 6c 20 6f 72 20 6f 74 | 68 65 72 20 66 75 6e 63 |ll or ot|her func|
|000009c0| 74 69 6f 6e 20 74 68 61 | 74 20 69 73 20 6f 6e 6c |tion tha|t is onl|
|000009d0| 79 20 61 63 63 65 73 73 | 69 62 6c 65 20 66 72 6f |y access|ible fro|
|000009e0| 6d 20 43 20 5c 6c 64 6f | 74 73 20 20 55 73 75 61 |m C \ldo|ts Usua|
|000009f0| 6c 6c 79 0a 74 68 65 20 | 70 72 6f 62 6c 65 6d 20 |lly.the |problem |
|00000a00| 61 74 20 68 61 6e 64 20 | 69 73 6e 27 74 20 73 65 |at hand |isn't se|
|00000a10| 72 69 6f 75 73 20 65 6e | 6f 75 67 68 20 74 6f 20 |rious en|ough to |
|00000a20| 77 61 72 72 61 6e 74 20 | 72 65 77 72 69 74 69 6e |warrant |rewritin|
|00000a30| 67 20 74 68 65 0a 73 63 | 72 69 70 74 20 69 6e 20 |g the.sc|ript in |
|00000a40| 43 3b 20 70 65 72 68 61 | 70 73 20 62 65 63 61 75 |C; perha|ps becau|
|00000a50| 73 65 20 74 68 65 20 70 | 72 6f 62 6c 65 6d 20 72 |se the p|roblem r|
|00000a60| 65 71 75 69 72 65 73 20 | 76 61 72 69 61 62 6c 65 |equires |variable|
|00000a70| 2d 6c 65 6e 67 74 68 0a | 73 74 72 69 6e 67 73 20 |-length.|strings |
|00000a80| 6f 72 20 6f 74 68 65 72 | 20 64 61 74 61 20 74 79 |or other| data ty|
|00000a90| 70 65 73 20 28 6c 69 6b | 65 20 73 6f 72 74 65 64 |pes (lik|e sorted|
|00000aa0| 20 6c 69 73 74 73 20 6f | 66 20 66 69 6c 65 20 6e | lists o|f file n|
|00000ab0| 61 6d 65 73 29 20 74 68 | 61 74 20 61 72 65 0a 65 |ames) th|at are.e|
|00000ac0| 61 73 79 20 69 6e 20 74 | 68 65 20 73 68 65 6c 6c |asy in t|he shell|
|00000ad0| 20 62 75 74 20 6c 6f 74 | 73 20 6f 66 20 77 6f 72 | but lot|s of wor|
|00000ae0| 6b 20 74 6f 20 69 6d 70 | 6c 65 6d 65 6e 74 20 69 |k to imp|lement i|
|00000af0| 6e 20 43 3b 20 6f 72 20 | 70 65 72 68 61 70 73 20 |n C; or |perhaps |
|00000b00| 6a 75 73 74 0a 62 65 63 | 61 75 73 65 20 79 6f 75 |just.bec|ause you|
|00000b10| 27 72 65 20 6e 6f 74 20 | 73 75 66 66 69 63 69 65 |'re not |sufficie|
|00000b20| 6e 74 6c 79 20 66 61 6d | 69 6c 69 61 72 20 77 69 |ntly fam|iliar wi|
|00000b30| 74 68 20 43 2e 0a 0a 49 | 6e 20 73 75 63 68 20 63 |th C...I|n such c|
|00000b40| 61 73 65 73 2c 20 50 79 | 74 68 6f 6e 20 6d 61 79 |ases, Py|thon may|
|00000b50| 20 62 65 20 6a 75 73 74 | 20 74 68 65 20 6c 61 6e | be just| the lan|
|00000b60| 67 75 61 67 65 20 66 6f | 72 20 79 6f 75 2e 20 20 |guage fo|r you. |
|00000b70| 50 79 74 68 6f 6e 20 69 | 73 0a 73 69 6d 70 6c 65 |Python i|s.simple|
|00000b80| 20 74 6f 20 75 73 65 2c | 20 62 75 74 20 69 74 20 | to use,| but it |
|00000b90| 69 73 20 61 20 72 65 61 | 6c 20 70 72 6f 67 72 61 |is a rea|l progra|
|00000ba0| 6d 6d 69 6e 67 20 6c 61 | 6e 67 75 61 67 65 2c 20 |mming la|nguage, |
|00000bb0| 6f 66 66 65 72 69 6e 67 | 20 6d 75 63 68 0a 6d 6f |offering| much.mo|
|00000bc0| 72 65 20 73 74 72 75 63 | 74 75 72 65 20 61 6e 64 |re struc|ture and|
|00000bd0| 20 73 75 70 70 6f 72 74 | 20 66 6f 72 20 6c 61 72 | support| for lar|
|00000be0| 67 65 20 70 72 6f 67 72 | 61 6d 73 20 74 68 61 6e |ge progr|ams than|
|00000bf0| 20 74 68 65 20 73 68 65 | 6c 6c 20 68 61 73 2e 20 | the she|ll has. |
|00000c00| 20 4f 6e 0a 74 68 65 20 | 6f 74 68 65 72 20 68 61 | On.the |other ha|
|00000c10| 6e 64 2c 20 69 74 20 61 | 6c 73 6f 20 6f 66 66 65 |nd, it a|lso offe|
|00000c20| 72 73 20 6d 75 63 68 20 | 6d 6f 72 65 20 65 72 72 |rs much |more err|
|00000c30| 6f 72 20 63 68 65 63 6b | 69 6e 67 20 74 68 61 6e |or check|ing than|
|00000c40| 20 43 2c 20 61 6e 64 2c | 0a 62 65 69 6e 67 20 61 | C, and,|.being a|
|00000c50| 20 7b 5c 65 6d 20 76 65 | 72 79 2d 68 69 67 68 2d | {\em ve|ry-high-|
|00000c60| 6c 65 76 65 6c 20 6c 61 | 6e 67 75 61 67 65 7d 2c |level la|nguage},|
|00000c70| 20 69 74 20 68 61 73 20 | 68 69 67 68 2d 6c 65 76 | it has |high-lev|
|00000c80| 65 6c 20 64 61 74 61 20 | 74 79 70 65 73 0a 62 75 |el data |types.bu|
|00000c90| 69 6c 74 20 69 6e 2c 20 | 73 75 63 68 20 61 73 20 |ilt in, |such as |
|00000ca0| 66 6c 65 78 69 62 6c 65 | 20 61 72 72 61 79 73 20 |flexible| arrays |
|00000cb0| 61 6e 64 20 64 69 63 74 | 69 6f 6e 61 72 69 65 73 |and dict|ionaries|
|00000cc0| 20 74 68 61 74 20 77 6f | 75 6c 64 20 63 6f 73 74 | that wo|uld cost|
|00000cd0| 20 79 6f 75 0a 64 61 79 | 73 20 74 6f 20 69 6d 70 | you.day|s to imp|
|00000ce0| 6c 65 6d 65 6e 74 20 65 | 66 66 69 63 69 65 6e 74 |lement e|fficient|
|00000cf0| 6c 79 20 69 6e 20 43 2e | 20 20 42 65 63 61 75 73 |ly in C.| Becaus|
|00000d00| 65 20 6f 66 20 69 74 73 | 20 6d 6f 72 65 20 67 65 |e of its| more ge|
|00000d10| 6e 65 72 61 6c 20 64 61 | 74 61 0a 74 79 70 65 73 |neral da|ta.types|
|00000d20| 20 50 79 74 68 6f 6e 20 | 69 73 20 61 70 70 6c 69 | Python |is appli|
|00000d30| 63 61 62 6c 65 20 74 6f | 20 61 20 6d 75 63 68 20 |cable to| a much |
|00000d40| 6c 61 72 67 65 72 20 70 | 72 6f 62 6c 65 6d 20 64 |larger p|roblem d|
|00000d50| 6f 6d 61 69 6e 20 74 68 | 61 6e 20 7b 5c 65 6d 0a |omain th|an {\em.|
|00000d60| 41 77 6b 7d 20 6f 72 20 | 65 76 65 6e 20 7b 5c 65 |Awk} or |even {\e|
|00000d70| 6d 20 50 65 72 6c 7d 2c | 20 79 65 74 20 6d 61 6e |m Perl},| yet man|
|00000d80| 79 20 74 68 69 6e 67 73 | 20 61 72 65 20 61 74 20 |y things| are at |
|00000d90| 6c 65 61 73 74 20 61 73 | 20 65 61 73 79 20 69 6e |least as| easy in|
|00000da0| 0a 50 79 74 68 6f 6e 20 | 61 73 20 69 6e 20 74 68 |.Python |as in th|
|00000db0| 6f 73 65 20 6c 61 6e 67 | 75 61 67 65 73 2e 0a 0a |ose lang|uages...|
|00000dc0| 50 79 74 68 6f 6e 20 61 | 6c 6c 6f 77 73 20 79 6f |Python a|llows yo|
|00000dd0| 75 20 74 6f 20 73 70 6c | 69 74 20 75 70 20 79 6f |u to spl|it up yo|
|00000de0| 75 72 20 70 72 6f 67 72 | 61 6d 20 69 6e 20 6d 6f |ur progr|am in mo|
|00000df0| 64 75 6c 65 73 20 74 68 | 61 74 20 63 61 6e 20 62 |dules th|at can b|
|00000e00| 65 0a 72 65 75 73 65 64 | 20 69 6e 20 6f 74 68 65 |e.reused| in othe|
|00000e10| 72 20 50 79 74 68 6f 6e | 20 70 72 6f 67 72 61 6d |r Python| program|
|00000e20| 73 2e 20 20 49 74 20 63 | 6f 6d 65 73 20 77 69 74 |s. It c|omes wit|
|00000e30| 68 20 61 20 6c 61 72 67 | 65 20 63 6f 6c 6c 65 63 |h a larg|e collec|
|00000e40| 74 69 6f 6e 20 6f 66 0a | 73 74 61 6e 64 61 72 64 |tion of.|standard|
|00000e50| 20 6d 6f 64 75 6c 65 73 | 20 74 68 61 74 20 79 6f | modules| that yo|
|00000e60| 75 20 63 61 6e 20 75 73 | 65 20 61 73 20 74 68 65 |u can us|e as the|
|00000e70| 20 62 61 73 69 73 20 6f | 66 20 79 6f 75 72 20 70 | basis o|f your p|
|00000e80| 72 6f 67 72 61 6d 73 20 | 2d 2d 2d 20 6f 72 0a 61 |rograms |--- or.a|
|00000e90| 73 20 65 78 61 6d 70 6c | 65 73 20 74 6f 20 73 74 |s exampl|es to st|
|00000ea0| 61 72 74 20 6c 65 61 72 | 6e 69 6e 67 20 74 6f 20 |art lear|ning to |
|00000eb0| 70 72 6f 67 72 61 6d 20 | 69 6e 20 50 79 74 68 6f |program |in Pytho|
|00000ec0| 6e 2e 20 20 54 68 65 72 | 65 20 61 72 65 20 61 6c |n. Ther|e are al|
|00000ed0| 73 6f 0a 62 75 69 6c 74 | 2d 69 6e 20 6d 6f 64 75 |so.built|-in modu|
|00000ee0| 6c 65 73 20 74 68 61 74 | 20 70 72 6f 76 69 64 65 |les that| provide|
|00000ef0| 20 74 68 69 6e 67 73 20 | 6c 69 6b 65 20 66 69 6c | things |like fil|
|00000f00| 65 20 49 2f 4f 2c 20 73 | 79 73 74 65 6d 20 63 61 |e I/O, s|ystem ca|
|00000f10| 6c 6c 73 2c 0a 73 6f 63 | 6b 65 74 73 2c 20 61 6e |lls,.soc|kets, an|
|00000f20| 64 20 65 76 65 6e 20 61 | 20 67 65 6e 65 72 69 63 |d even a| generic|
|00000f30| 20 69 6e 74 65 72 66 61 | 63 65 20 74 6f 20 77 69 | interfa|ce to wi|
|00000f40| 6e 64 6f 77 20 73 79 73 | 74 65 6d 73 20 28 53 54 |ndow sys|tems (ST|
|00000f50| 44 57 49 4e 29 2e 0a 0a | 50 79 74 68 6f 6e 20 69 |DWIN)...|Python i|
|00000f60| 73 20 61 6e 20 69 6e 74 | 65 72 70 72 65 74 65 64 |s an int|erpreted|
|00000f70| 20 6c 61 6e 67 75 61 67 | 65 2c 20 77 68 69 63 68 | languag|e, which|
|00000f80| 20 63 61 6e 20 73 61 76 | 65 20 79 6f 75 20 63 6f | can sav|e you co|
|00000f90| 6e 73 69 64 65 72 61 62 | 6c 65 20 74 69 6d 65 0a |nsiderab|le time.|
|00000fa0| 64 75 72 69 6e 67 20 70 | 72 6f 67 72 61 6d 20 64 |during p|rogram d|
|00000fb0| 65 76 65 6c 6f 70 6d 65 | 6e 74 20 62 65 63 61 75 |evelopme|nt becau|
|00000fc0| 73 65 20 6e 6f 20 63 6f | 6d 70 69 6c 61 74 69 6f |se no co|mpilatio|
|00000fd0| 6e 20 61 6e 64 20 6c 69 | 6e 6b 69 6e 67 20 69 73 |n and li|nking is|
|00000fe0| 0a 6e 65 63 65 73 73 61 | 72 79 2e 20 20 54 68 65 |.necessa|ry. The|
|00000ff0| 20 69 6e 74 65 72 70 72 | 65 74 65 72 20 63 61 6e | interpr|eter can|
|00001000| 20 62 65 20 75 73 65 64 | 20 69 6e 74 65 72 61 63 | be used| interac|
|00001010| 74 69 76 65 6c 79 2c 20 | 77 68 69 63 68 20 6d 61 |tively, |which ma|
|00001020| 6b 65 73 20 69 74 0a 65 | 61 73 79 20 74 6f 20 65 |kes it.e|asy to e|
|00001030| 78 70 65 72 69 6d 65 6e | 74 20 77 69 74 68 20 66 |xperimen|t with f|
|00001040| 65 61 74 75 72 65 73 20 | 6f 66 20 74 68 65 20 6c |eatures |of the l|
|00001050| 61 6e 67 75 61 67 65 2c | 20 74 6f 20 77 72 69 74 |anguage,| to writ|
|00001060| 65 20 74 68 72 6f 77 2d | 61 77 61 79 0a 70 72 6f |e throw-|away.pro|
|00001070| 67 72 61 6d 73 2c 20 6f | 72 20 74 6f 20 74 65 73 |grams, o|r to tes|
|00001080| 74 20 66 75 6e 63 74 69 | 6f 6e 73 20 64 75 72 69 |t functi|ons duri|
|00001090| 6e 67 20 62 6f 74 74 6f | 6d 2d 75 70 20 70 72 6f |ng botto|m-up pro|
|000010a0| 67 72 61 6d 20 64 65 76 | 65 6c 6f 70 6d 65 6e 74 |gram dev|elopment|
|000010b0| 2e 0a 49 74 20 69 73 20 | 61 6c 73 6f 20 61 20 68 |..It is |also a h|
|000010c0| 61 6e 64 79 20 64 65 73 | 6b 20 63 61 6c 63 75 6c |andy des|k calcul|
|000010d0| 61 74 6f 72 2e 0a 0a 50 | 79 74 68 6f 6e 20 61 6c |ator...P|ython al|
|000010e0| 6c 6f 77 73 20 77 72 69 | 74 69 6e 67 20 76 65 72 |lows wri|ting ver|
|000010f0| 79 20 63 6f 6d 70 61 63 | 74 20 61 6e 64 20 72 65 |y compac|t and re|
|00001100| 61 64 61 62 6c 65 20 70 | 72 6f 67 72 61 6d 73 2e |adable p|rograms.|
|00001110| 20 20 50 72 6f 67 72 61 | 6d 73 0a 77 72 69 74 74 | Progra|ms.writt|
|00001120| 65 6e 20 69 6e 20 50 79 | 74 68 6f 6e 20 61 72 65 |en in Py|thon are|
|00001130| 20 74 79 70 69 63 61 6c | 6c 79 20 6d 75 63 68 20 | typical|ly much |
|00001140| 73 68 6f 72 74 65 72 20 | 74 68 61 6e 20 65 71 75 |shorter |than equ|
|00001150| 69 76 61 6c 65 6e 74 20 | 43 0a 70 72 6f 67 72 61 |ivalent |C.progra|
|00001160| 6d 73 2c 20 66 6f 72 20 | 73 65 76 65 72 61 6c 20 |ms, for |several |
|00001170| 72 65 61 73 6f 6e 73 3a | 0a 5c 62 65 67 69 6e 7b |reasons:|.\begin{|
|00001180| 69 74 65 6d 69 7a 65 7d | 0a 5c 69 74 65 6d 0a 74 |itemize}|.\item.t|
|00001190| 68 65 20 68 69 67 68 2d | 6c 65 76 65 6c 20 64 61 |he high-|level da|
|000011a0| 74 61 20 74 79 70 65 73 | 20 61 6c 6c 6f 77 20 79 |ta types| allow y|
|000011b0| 6f 75 20 74 6f 20 65 78 | 70 72 65 73 73 20 63 6f |ou to ex|press co|
|000011c0| 6d 70 6c 65 78 20 6f 70 | 65 72 61 74 69 6f 6e 73 |mplex op|erations|
|000011d0| 20 69 6e 20 61 0a 73 69 | 6e 67 6c 65 20 73 74 61 | in a.si|ngle sta|
|000011e0| 74 65 6d 65 6e 74 3b 0a | 5c 69 74 65 6d 0a 73 74 |tement;.|\item.st|
|000011f0| 61 74 65 6d 65 6e 74 20 | 67 72 6f 75 70 69 6e 67 |atement |grouping|
|00001200| 20 69 73 20 64 6f 6e 65 | 20 62 79 20 69 6e 64 65 | is done| by inde|
|00001210| 6e 74 61 74 69 6f 6e 20 | 69 6e 73 74 65 61 64 20 |ntation |instead |
|00001220| 6f 66 20 62 65 67 69 6e | 2f 65 6e 64 0a 62 72 61 |of begin|/end.bra|
|00001230| 63 6b 65 74 73 3b 0a 5c | 69 74 65 6d 0a 6e 6f 20 |ckets;.\|item.no |
|00001240| 76 61 72 69 61 62 6c 65 | 20 6f 72 20 61 72 67 75 |variable| or argu|
|00001250| 6d 65 6e 74 20 64 65 63 | 6c 61 72 61 74 69 6f 6e |ment dec|laration|
|00001260| 73 20 61 72 65 20 6e 65 | 63 65 73 73 61 72 79 2e |s are ne|cessary.|
|00001270| 0a 5c 65 6e 64 7b 69 74 | 65 6d 69 7a 65 7d 0a 0a |.\end{it|emize}..|
|00001280| 50 79 74 68 6f 6e 20 69 | 73 20 7b 5c 65 6d 20 65 |Python i|s {\em e|
|00001290| 78 74 65 6e 73 69 62 6c | 65 7d 3a 20 69 66 20 79 |xtensibl|e}: if y|
|000012a0| 6f 75 20 6b 6e 6f 77 20 | 68 6f 77 20 74 6f 20 70 |ou know |how to p|
|000012b0| 72 6f 67 72 61 6d 20 69 | 6e 20 43 20 69 74 20 69 |rogram i|n C it i|
|000012c0| 73 20 65 61 73 79 0a 74 | 6f 20 61 64 64 20 61 20 |s easy.t|o add a |
|000012d0| 6e 65 77 20 62 75 69 6c | 74 2d 69 6e 0a 66 75 6e |new buil|t-in.fun|
|000012e0| 63 74 69 6f 6e 20 6f 72 | 0a 6d 6f 64 75 6c 65 20 |ction or|.module |
|000012f0| 74 6f 20 74 68 65 20 69 | 6e 74 65 72 70 72 65 74 |to the i|nterpret|
|00001300| 65 72 2c 20 65 69 74 68 | 65 72 20 74 6f 0a 70 65 |er, eith|er to.pe|
|00001310| 72 66 6f 72 6d 20 63 72 | 69 74 69 63 61 6c 20 6f |rform cr|itical o|
|00001320| 70 65 72 61 74 69 6f 6e | 73 20 61 74 20 6d 61 78 |peration|s at max|
|00001330| 69 6d 75 6d 20 73 70 65 | 65 64 2c 20 6f 72 20 74 |imum spe|ed, or t|
|00001340| 6f 20 6c 69 6e 6b 20 50 | 79 74 68 6f 6e 0a 70 72 |o link P|ython.pr|
|00001350| 6f 67 72 61 6d 73 20 74 | 6f 20 6c 69 62 72 61 72 |ograms t|o librar|
|00001360| 69 65 73 20 74 68 61 74 | 20 6d 61 79 20 6f 6e 6c |ies that| may onl|
|00001370| 79 20 62 65 20 61 76 61 | 69 6c 61 62 6c 65 20 69 |y be ava|ilable i|
|00001380| 6e 20 62 69 6e 61 72 79 | 20 66 6f 72 6d 20 28 73 |n binary| form (s|
|00001390| 75 63 68 0a 61 73 20 61 | 20 76 65 6e 64 6f 72 2d |uch.as a| vendor-|
|000013a0| 73 70 65 63 69 66 69 63 | 20 67 72 61 70 68 69 63 |specific| graphic|
|000013b0| 73 20 6c 69 62 72 61 72 | 79 29 2e 20 20 4f 6e 63 |s librar|y). Onc|
|000013c0| 65 20 79 6f 75 20 61 72 | 65 20 72 65 61 6c 6c 79 |e you ar|e really|
|000013d0| 20 68 6f 6f 6b 65 64 2c | 0a 79 6f 75 20 63 61 6e | hooked,|.you can|
|000013e0| 20 6c 69 6e 6b 20 74 68 | 65 20 50 79 74 68 6f 6e | link th|e Python|
|000013f0| 20 69 6e 74 65 72 70 72 | 65 74 65 72 20 69 6e 74 | interpr|eter int|
|00001400| 6f 20 61 6e 20 61 70 70 | 6c 69 63 61 74 69 6f 6e |o an app|lication|
|00001410| 20 77 72 69 74 74 65 6e | 20 69 6e 20 43 0a 61 6e | written| in C.an|
|00001420| 64 20 75 73 65 20 69 74 | 20 61 73 20 61 6e 20 65 |d use it| as an e|
|00001430| 78 74 65 6e 73 69 6f 6e | 20 6f 72 20 63 6f 6d 6d |xtension| or comm|
|00001440| 61 6e 64 20 6c 61 6e 67 | 75 61 67 65 20 66 6f 72 |and lang|uage for|
|00001450| 20 74 68 61 74 20 61 70 | 70 6c 69 63 61 74 69 6f | that ap|plicatio|
|00001460| 6e 2e 0a 0a 42 79 20 74 | 68 65 20 77 61 79 2c 20 |n...By t|he way, |
|00001470| 74 68 65 20 6c 61 6e 67 | 75 61 67 65 20 69 73 20 |the lang|uage is |
|00001480| 6e 61 6d 65 64 20 61 66 | 74 65 72 20 74 68 65 20 |named af|ter the |
|00001490| 42 42 43 20 73 68 6f 77 | 20 60 60 4d 6f 6e 74 79 |BBC show| ``Monty|
|000014a0| 0a 50 79 74 68 6f 6e 27 | 73 20 46 6c 79 69 6e 67 |.Python'|s Flying|
|000014b0| 20 43 69 72 63 75 73 27 | 27 20 61 6e 64 20 68 61 | Circus'|' and ha|
|000014c0| 73 20 6e 6f 74 68 69 6e | 67 20 74 6f 20 64 6f 20 |s nothin|g to do |
|000014d0| 77 69 74 68 20 6e 61 73 | 74 79 20 72 65 70 74 69 |with nas|ty repti|
|000014e0| 6c 65 73 2e 2e 2e 0a 0a | 5c 73 65 63 74 69 6f 6e |les.....|\section|
|000014f0| 7b 57 68 65 72 65 20 46 | 72 6f 6d 20 48 65 72 65 |{Where F|rom Here|
|00001500| 7d 0a 0a 4e 6f 77 20 74 | 68 61 74 20 79 6f 75 20 |}..Now t|hat you |
|00001510| 61 72 65 20 61 6c 6c 20 | 65 78 63 69 74 65 64 20 |are all |excited |
|00001520| 61 62 6f 75 74 20 50 79 | 74 68 6f 6e 2c 20 79 6f |about Py|thon, yo|
|00001530| 75 27 6c 6c 20 77 61 6e | 74 20 74 6f 20 65 78 61 |u'll wan|t to exa|
|00001540| 6d 69 6e 65 20 69 74 0a | 69 6e 20 73 6f 6d 65 20 |mine it.|in some |
|00001550| 6d 6f 72 65 20 64 65 74 | 61 69 6c 2e 20 20 53 69 |more det|ail. Si|
|00001560| 6e 63 65 20 74 68 65 20 | 62 65 73 74 20 77 61 79 |nce the |best way|
|00001570| 20 74 6f 20 6c 65 61 72 | 6e 20 61 20 6c 61 6e 67 | to lear|n a lang|
|00001580| 75 61 67 65 20 69 73 0a | 75 73 69 6e 67 20 69 74 |uage is.|using it|
|00001590| 2c 20 79 6f 75 20 61 72 | 65 20 69 6e 76 69 74 65 |, you ar|e invite|
|000015a0| 64 20 68 65 72 65 20 74 | 6f 20 64 6f 20 73 6f 2e |d here t|o do so.|
|000015b0| 0a 0a 49 6e 20 74 68 65 | 20 6e 65 78 74 20 63 68 |..In the| next ch|
|000015c0| 61 70 74 65 72 2c 20 74 | 68 65 20 6d 65 63 68 61 |apter, t|he mecha|
|000015d0| 6e 69 63 73 20 6f 66 20 | 75 73 69 6e 67 20 74 68 |nics of |using th|
|000015e0| 65 20 69 6e 74 65 72 70 | 72 65 74 65 72 20 61 72 |e interp|reter ar|
|000015f0| 65 0a 65 78 70 6c 61 69 | 6e 65 64 2e 20 20 54 68 |e.explai|ned. Th|
|00001600| 69 73 20 69 73 20 72 61 | 74 68 65 72 20 6d 75 6e |is is ra|ther mun|
|00001610| 64 61 6e 65 20 69 6e 66 | 6f 72 6d 61 74 69 6f 6e |dane inf|ormation|
|00001620| 2c 20 62 75 74 20 65 73 | 73 65 6e 74 69 61 6c 20 |, but es|sential |
|00001630| 66 6f 72 0a 74 72 79 69 | 6e 67 20 6f 75 74 20 74 |for.tryi|ng out t|
|00001640| 68 65 20 65 78 61 6d 70 | 6c 65 73 20 73 68 6f 77 |he examp|les show|
|00001650| 6e 20 6c 61 74 65 72 2e | 0a 0a 54 68 65 20 72 65 |n later.|..The re|
|00001660| 73 74 20 6f 66 20 74 68 | 65 20 74 75 74 6f 72 69 |st of th|e tutori|
|00001670| 61 6c 20 69 6e 74 72 6f | 64 75 63 65 73 20 76 61 |al intro|duces va|
|00001680| 72 69 6f 75 73 20 66 65 | 61 74 75 72 65 73 20 6f |rious fe|atures o|
|00001690| 66 20 74 68 65 20 50 79 | 74 68 6f 6e 0a 6c 61 6e |f the Py|thon.lan|
|000016a0| 67 75 61 67 65 20 61 6e | 64 20 73 79 73 74 65 6d |guage an|d system|
|000016b0| 20 74 68 6f 75 67 68 20 | 65 78 61 6d 70 6c 65 73 | though |examples|
|000016c0| 2c 20 62 65 67 69 6e 6e | 69 6e 67 20 77 69 74 68 |, beginn|ing with|
|000016d0| 20 73 69 6d 70 6c 65 0a | 65 78 70 72 65 73 73 69 | simple.|expressi|
|000016e0| 6f 6e 73 2c 20 73 74 61 | 74 65 6d 65 6e 74 73 20 |ons, sta|tements |
|000016f0| 61 6e 64 20 64 61 74 61 | 20 74 79 70 65 73 2c 20 |and data| types, |
|00001700| 74 68 72 6f 75 67 68 20 | 66 75 6e 63 74 69 6f 6e |through |function|
|00001710| 73 20 61 6e 64 20 6d 6f | 64 75 6c 65 73 2c 0a 61 |s and mo|dules,.a|
|00001720| 6e 64 20 66 69 6e 61 6c | 6c 79 20 74 6f 75 63 68 |nd final|ly touch|
|00001730| 69 6e 67 20 75 70 6f 6e | 20 61 64 76 61 6e 63 65 |ing upon| advance|
|00001740| 64 20 63 6f 6e 63 65 70 | 74 73 20 6c 69 6b 65 20 |d concep|ts like |
|00001750| 65 78 63 65 70 74 69 6f | 6e 73 0a 61 6e 64 20 75 |exceptio|ns.and u|
|00001760| 73 65 72 2d 64 65 66 69 | 6e 65 64 20 63 6c 61 73 |ser-defi|ned clas|
|00001770| 73 65 73 2e 0a 0a 57 68 | 65 6e 20 79 6f 75 27 72 |ses...Wh|en you'r|
|00001780| 65 20 74 68 72 6f 75 67 | 68 20 77 69 74 68 20 74 |e throug|h with t|
|00001790| 68 65 20 74 75 74 6f 72 | 69 61 6c 20 28 6f 72 20 |he tutor|ial (or |
|000017a0| 6a 75 73 74 20 67 65 74 | 74 69 6e 67 20 62 6f 72 |just get|ting bor|
|000017b0| 65 64 29 2c 20 79 6f 75 | 0a 73 68 6f 75 6c 64 20 |ed), you|.should |
|000017c0| 72 65 61 64 20 74 68 65 | 20 4c 69 62 72 61 72 79 |read the| Library|
|000017d0| 20 52 65 66 65 72 65 6e | 63 65 2c 20 77 68 69 63 | Referen|ce, whic|
|000017e0| 68 20 67 69 76 65 73 20 | 63 6f 6d 70 6c 65 74 65 |h gives |complete|
|000017f0| 20 28 74 68 6f 75 67 68 | 20 74 65 72 73 65 29 0a | (though| terse).|
|00001800| 72 65 66 65 72 65 6e 63 | 65 20 6d 61 74 65 72 69 |referenc|e materi|
|00001810| 61 6c 20 61 62 6f 75 74 | 20 62 75 69 6c 74 2d 69 |al about| built-i|
|00001820| 6e 20 61 6e 64 20 73 74 | 61 6e 64 61 72 64 20 74 |n and st|andard t|
|00001830| 79 70 65 73 2c 20 66 75 | 6e 63 74 69 6f 6e 73 20 |ypes, fu|nctions |
|00001840| 61 6e 64 0a 6d 6f 64 75 | 6c 65 73 20 74 68 61 74 |and.modu|les that|
|00001850| 20 63 61 6e 20 73 61 76 | 65 20 79 6f 75 20 61 20 | can sav|e you a |
|00001860| 6c 6f 74 20 6f 66 20 74 | 69 6d 65 20 77 68 65 6e |lot of t|ime when|
|00001870| 20 77 72 69 74 69 6e 67 | 20 50 79 74 68 6f 6e 20 | writing| Python |
|00001880| 70 72 6f 67 72 61 6d 73 | 2e 0a 0a 0a 5c 63 68 61 |programs|....\cha|
|00001890| 70 74 65 72 7b 55 73 69 | 6e 67 20 74 68 65 20 50 |pter{Usi|ng the P|
|000018a0| 79 74 68 6f 6e 20 49 6e | 74 65 72 70 72 65 74 65 |ython In|terprete|
|000018b0| 72 7d 0a 0a 5c 73 65 63 | 74 69 6f 6e 7b 49 6e 76 |r}..\sec|tion{Inv|
|000018c0| 6f 6b 69 6e 67 20 74 68 | 65 20 49 6e 74 65 72 70 |oking th|e Interp|
|000018d0| 72 65 74 65 72 7d 0a 0a | 54 68 65 20 50 79 74 68 |reter}..|The Pyth|
|000018e0| 6f 6e 20 69 6e 74 65 72 | 70 72 65 74 65 72 20 69 |on inter|preter i|
|000018f0| 73 20 75 73 75 61 6c 6c | 79 20 69 6e 73 74 61 6c |s usuall|y instal|
|00001900| 6c 65 64 20 61 73 20 7b | 5c 74 74 20 2f 75 73 72 |led as {|\tt /usr|
|00001910| 2f 6c 6f 63 61 6c 2f 62 | 69 6e 2f 70 79 74 68 6f |/local/b|in/pytho|
|00001920| 6e 7d 0a 6f 6e 20 74 68 | 6f 73 65 20 6d 61 63 68 |n}.on th|ose mach|
|00001930| 69 6e 65 73 20 77 68 65 | 72 65 20 69 74 20 69 73 |ines whe|re it is|
|00001940| 20 61 76 61 69 6c 61 62 | 6c 65 3b 20 70 75 74 74 | availab|le; putt|
|00001950| 69 6e 67 20 7b 5c 74 74 | 20 2f 75 73 72 2f 6c 6f |ing {\tt| /usr/lo|
|00001960| 63 61 6c 2f 62 69 6e 7d | 20 69 6e 0a 79 6f 75 72 |cal/bin}| in.your|
|00001970| 20 7b 5c 55 4e 49 58 7d | 20 73 68 65 6c 6c 27 73 | {\UNIX}| shell's|
|00001980| 20 73 65 61 72 63 68 20 | 70 61 74 68 20 6d 61 6b | search |path mak|
|00001990| 65 73 20 69 74 20 70 6f | 73 73 69 62 6c 65 20 74 |es it po|ssible t|
|000019a0| 6f 20 73 74 61 72 74 20 | 69 74 20 62 79 0a 74 79 |o start |it by.ty|
|000019b0| 70 69 6e 67 20 74 68 65 | 20 63 6f 6d 6d 61 6e 64 |ping the| command|
|000019c0| 0a 0a 5c 62 63 6f 64 65 | 5c 62 65 67 69 6e 7b 76 |..\bcode|\begin{v|
|000019d0| 65 72 62 61 74 69 6d 7d | 0a 70 79 74 68 6f 6e 0a |erbatim}|.python.|
|000019e0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|000019f0| 63 6f 64 65 0a 25 0a 74 | 6f 20 74 68 65 20 73 68 |code.%.t|o the sh|
|00001a00| 65 6c 6c 2e 20 20 53 69 | 6e 63 65 20 74 68 65 20 |ell. Si|nce the |
|00001a10| 63 68 6f 69 63 65 20 6f | 66 20 74 68 65 20 64 69 |choice o|f the di|
|00001a20| 72 65 63 74 6f 72 79 20 | 77 68 65 72 65 20 74 68 |rectory |where th|
|00001a30| 65 20 69 6e 74 65 72 70 | 72 65 74 65 72 0a 6c 69 |e interp|reter.li|
|00001a40| 76 65 73 20 69 73 20 61 | 6e 20 69 6e 73 74 61 6c |ves is a|n instal|
|00001a50| 6c 61 74 69 6f 6e 20 6f | 70 74 69 6f 6e 2c 20 6f |lation o|ption, o|
|00001a60| 74 68 65 72 20 70 6c 61 | 63 65 73 20 61 72 65 20 |ther pla|ces are |
|00001a70| 70 6f 73 73 69 62 6c 65 | 3b 20 63 68 65 63 6b 20 |possible|; check |
|00001a80| 77 69 74 68 0a 79 6f 75 | 72 20 6c 6f 63 61 6c 20 |with.you|r local |
|00001a90| 50 79 74 68 6f 6e 20 67 | 75 72 75 20 6f 72 20 73 |Python g|uru or s|
|00001aa0| 79 73 74 65 6d 20 61 64 | 6d 69 6e 69 73 74 72 61 |ystem ad|ministra|
|00001ab0| 74 6f 72 2e 20 20 28 45 | 2e 67 2e 2c 20 7b 5c 74 |tor. (E|.g., {\t|
|00001ac0| 74 0a 2f 75 73 72 2f 6c | 6f 63 61 6c 2f 70 79 74 |t./usr/l|ocal/pyt|
|00001ad0| 68 6f 6e 7d 20 69 73 20 | 61 20 70 6f 70 75 6c 61 |hon} is |a popula|
|00001ae0| 72 20 61 6c 74 65 72 6e | 61 74 69 76 65 20 6c 6f |r altern|ative lo|
|00001af0| 63 61 74 69 6f 6e 2e 29 | 0a 0a 54 68 65 20 69 6e |cation.)|..The in|
|00001b00| 74 65 72 70 72 65 74 65 | 72 20 6f 70 65 72 61 74 |terprete|r operat|
|00001b10| 65 73 20 73 6f 6d 65 77 | 68 61 74 20 6c 69 6b 65 |es somew|hat like|
|00001b20| 20 74 68 65 20 7b 5c 55 | 4e 49 58 7d 20 73 68 65 | the {\U|NIX} she|
|00001b30| 6c 6c 3a 20 77 68 65 6e | 20 63 61 6c 6c 65 64 0a |ll: when| called.|
|00001b40| 77 69 74 68 20 73 74 61 | 6e 64 61 72 64 20 69 6e |with sta|ndard in|
|00001b50| 70 75 74 20 63 6f 6e 6e | 65 63 74 65 64 20 74 6f |put conn|ected to|
|00001b60| 20 61 20 74 74 79 20 64 | 65 76 69 63 65 2c 20 69 | a tty d|evice, i|
|00001b70| 74 20 72 65 61 64 73 20 | 61 6e 64 20 65 78 65 63 |t reads |and exec|
|00001b80| 75 74 65 73 0a 63 6f 6d | 6d 61 6e 64 73 20 69 6e |utes.com|mands in|
|00001b90| 74 65 72 61 63 74 69 76 | 65 6c 79 3b 20 77 68 65 |teractiv|ely; whe|
|00001ba0| 6e 20 63 61 6c 6c 65 64 | 20 77 69 74 68 20 61 20 |n called| with a |
|00001bb0| 66 69 6c 65 20 6e 61 6d | 65 20 61 72 67 75 6d 65 |file nam|e argume|
|00001bc0| 6e 74 20 6f 72 20 77 69 | 74 68 0a 61 20 66 69 6c |nt or wi|th.a fil|
|00001bd0| 65 20 61 73 20 73 74 61 | 6e 64 61 72 64 20 69 6e |e as sta|ndard in|
|00001be0| 70 75 74 2c 20 69 74 20 | 72 65 61 64 73 20 61 6e |put, it |reads an|
|00001bf0| 64 20 65 78 65 63 75 74 | 65 73 20 61 20 7b 5c 65 |d execut|es a {\e|
|00001c00| 6d 20 73 63 72 69 70 74 | 7d 20 66 72 6f 6d 0a 74 |m script|} from.t|
|00001c10| 68 61 74 20 66 69 6c 65 | 2e 0a 0a 41 20 74 68 69 |hat file|...A thi|
|00001c20| 72 64 20 77 61 79 20 6f | 66 20 73 74 61 72 74 69 |rd way o|f starti|
|00001c30| 6e 67 20 74 68 65 20 69 | 6e 74 65 72 70 72 65 74 |ng the i|nterpret|
|00001c40| 65 72 20 69 73 0a 60 60 | 7b 5c 74 74 20 70 79 74 |er is.``|{\tt pyt|
|00001c50| 68 6f 6e 20 2d 63 20 63 | 6f 6d 6d 61 6e 64 20 5b |hon -c c|ommand [|
|00001c60| 61 72 67 5d 20 2e 2e 2e | 7d 27 27 2c 20 77 68 69 |arg] ...|}'', whi|
|00001c70| 63 68 0a 65 78 65 63 75 | 74 65 73 20 74 68 65 20 |ch.execu|tes the |
|00001c80| 73 74 61 74 65 6d 65 6e | 74 28 73 29 20 69 6e 20 |statemen|t(s) in |
|00001c90| 7b 5c 74 74 20 63 6f 6d | 6d 61 6e 64 7d 2c 20 61 |{\tt com|mand}, a|
|00001ca0| 6e 61 6c 6f 67 6f 75 73 | 20 74 6f 20 74 68 65 20 |nalogous| to the |
|00001cb0| 73 68 65 6c 6c 27 73 0a | 7b 5c 74 74 20 2d 63 7d |shell's.|{\tt -c}|
|00001cc0| 20 6f 70 74 69 6f 6e 2e | 20 20 53 69 6e 63 65 20 | option.| Since |
|00001cd0| 50 79 74 68 6f 6e 20 73 | 74 61 74 65 6d 65 6e 74 |Python s|tatement|
|00001ce0| 73 20 6f 66 74 65 6e 20 | 63 6f 6e 74 61 69 6e 20 |s often |contain |
|00001cf0| 73 70 61 63 65 73 20 6f | 72 20 6f 74 68 65 72 0a |spaces o|r other.|
|00001d00| 63 68 61 72 61 63 74 65 | 72 73 20 74 68 61 74 20 |characte|rs that |
|00001d10| 61 72 65 20 73 70 65 63 | 69 61 6c 20 74 6f 20 74 |are spec|ial to t|
|00001d20| 68 65 20 73 68 65 6c 6c | 2c 20 69 74 20 69 73 20 |he shell|, it is |
|00001d30| 62 65 73 74 20 74 6f 20 | 71 75 6f 74 65 20 7b 5c |best to |quote {\|
|00001d40| 74 74 0a 63 6f 6d 6d 61 | 6e 64 7d 20 69 6e 20 69 |tt.comma|nd} in i|
|00001d50| 74 73 20 65 6e 74 69 72 | 65 74 79 20 77 69 74 68 |ts entir|ety with|
|00001d60| 20 64 6f 75 62 6c 65 20 | 71 75 6f 74 65 73 2e 0a | double |quotes..|
|00001d70| 0a 4e 6f 74 65 20 74 68 | 61 74 20 74 68 65 72 65 |.Note th|at there|
|00001d80| 20 69 73 20 61 20 64 69 | 66 66 65 72 65 6e 63 65 | is a di|fference|
|00001d90| 20 62 65 74 77 65 65 6e | 20 60 60 7b 5c 74 74 20 | between| ``{\tt |
|00001da0| 70 79 74 68 6f 6e 20 66 | 69 6c 65 7d 27 27 20 61 |python f|ile}'' a|
|00001db0| 6e 64 0a 60 60 7b 5c 74 | 74 20 70 79 74 68 6f 6e |nd.``{\t|t python|
|00001dc0| 20 24 3c 24 66 69 6c 65 | 7d 27 27 2e 20 20 49 6e | $<$file|}''. In|
|00001dd0| 20 74 68 65 20 6c 61 74 | 74 65 72 20 63 61 73 65 | the lat|ter case|
|00001de0| 2c 20 69 6e 70 75 74 20 | 72 65 71 75 65 73 74 73 |, input |requests|
|00001df0| 20 66 72 6f 6d 20 74 68 | 65 0a 70 72 6f 67 72 61 | from th|e.progra|
|00001e00| 6d 2c 20 73 75 63 68 20 | 61 73 20 63 61 6c 6c 73 |m, such |as calls|
|00001e10| 20 74 6f 20 7b 5c 74 74 | 20 69 6e 70 75 74 28 29 | to {\tt| input()|
|00001e20| 7d 20 61 6e 64 20 7b 5c | 74 74 20 72 61 77 5f 69 |} and {\|tt raw_i|
|00001e30| 6e 70 75 74 28 29 7d 2c | 20 61 72 65 0a 73 61 74 |nput()},| are.sat|
|00001e40| 69 73 66 69 65 64 20 66 | 72 6f 6d 20 7b 5c 65 6d |isfied f|rom {\em|
|00001e50| 20 66 69 6c 65 7d 2e 20 | 20 53 69 6e 63 65 20 74 | file}. | Since t|
|00001e60| 68 69 73 20 66 69 6c 65 | 20 68 61 73 20 61 6c 72 |his file| has alr|
|00001e70| 65 61 64 79 20 62 65 65 | 6e 20 72 65 61 64 0a 75 |eady bee|n read.u|
|00001e80| 6e 74 69 6c 20 74 68 65 | 20 65 6e 64 20 62 79 20 |ntil the| end by |
|00001e90| 74 68 65 20 70 61 72 73 | 65 72 20 62 65 66 6f 72 |the pars|er befor|
|00001ea0| 65 20 74 68 65 20 70 72 | 6f 67 72 61 6d 20 73 74 |e the pr|ogram st|
|00001eb0| 61 72 74 73 20 65 78 65 | 63 75 74 69 6e 67 2c 20 |arts exe|cuting, |
|00001ec0| 74 68 65 0a 70 72 6f 67 | 72 61 6d 20 77 69 6c 6c |the.prog|ram will|
|00001ed0| 20 65 6e 63 6f 75 6e 74 | 65 72 20 45 4f 46 20 69 | encount|er EOF i|
|00001ee0| 6d 6d 65 64 69 61 74 65 | 6c 79 2e 20 20 49 6e 20 |mmediate|ly. In |
|00001ef0| 74 68 65 20 66 6f 72 6d | 65 72 20 63 61 73 65 20 |the form|er case |
|00001f00| 28 77 68 69 63 68 20 69 | 73 0a 75 73 75 61 6c 6c |(which i|s.usuall|
|00001f10| 79 20 77 68 61 74 20 79 | 6f 75 20 77 61 6e 74 29 |y what y|ou want)|
|00001f20| 20 74 68 65 79 20 61 72 | 65 20 73 61 74 69 73 66 | they ar|e satisf|
|00001f30| 69 65 64 20 66 72 6f 6d | 20 77 68 61 74 65 76 65 |ied from| whateve|
|00001f40| 72 20 66 69 6c 65 20 6f | 72 20 64 65 76 69 63 65 |r file o|r device|
|00001f50| 0a 69 73 20 63 6f 6e 6e | 65 63 74 65 64 20 74 6f |.is conn|ected to|
|00001f60| 20 73 74 61 6e 64 61 72 | 64 20 69 6e 70 75 74 20 | standar|d input |
|00001f70| 6f 66 20 74 68 65 20 50 | 79 74 68 6f 6e 20 69 6e |of the P|ython in|
|00001f80| 74 65 72 70 72 65 74 65 | 72 2e 0a 0a 57 68 65 6e |terprete|r...When|
|00001f90| 20 61 20 73 63 72 69 70 | 74 20 66 69 6c 65 20 69 | a scrip|t file i|
|00001fa0| 73 20 75 73 65 64 2c 20 | 69 74 20 69 73 20 73 6f |s used, |it is so|
|00001fb0| 6d 65 74 69 6d 65 73 20 | 75 73 65 66 75 6c 20 74 |metimes |useful t|
|00001fc0| 6f 20 62 65 20 61 62 6c | 65 20 74 6f 20 72 75 6e |o be abl|e to run|
|00001fd0| 0a 74 68 65 20 73 63 72 | 69 70 74 20 61 6e 64 20 |.the scr|ipt and |
|00001fe0| 65 6e 74 65 72 20 69 6e | 74 65 72 61 63 74 69 76 |enter in|teractiv|
|00001ff0| 65 20 6d 6f 64 65 20 61 | 66 74 65 72 77 61 72 64 |e mode a|fterward|
|00002000| 73 2e 20 20 54 68 69 73 | 20 63 61 6e 20 62 65 20 |s. This| can be |
|00002010| 64 6f 6e 65 20 62 79 0a | 70 61 73 73 69 6e 67 20 |done by.|passing |
|00002020| 7b 5c 74 74 20 2d 69 7d | 20 62 65 66 6f 72 65 20 |{\tt -i}| before |
|00002030| 74 68 65 20 73 63 72 69 | 70 74 2e 20 20 28 54 68 |the scri|pt. (Th|
|00002040| 69 73 20 64 6f 65 73 20 | 6e 6f 74 20 77 6f 72 6b |is does |not work|
|00002050| 20 69 66 20 74 68 65 20 | 73 63 72 69 70 74 0a 69 | if the |script.i|
|00002060| 73 20 72 65 61 64 20 66 | 72 6f 6d 20 73 74 61 6e |s read f|rom stan|
|00002070| 64 61 72 64 20 69 6e 70 | 75 74 2c 20 66 6f 72 20 |dard inp|ut, for |
|00002080| 74 68 65 20 73 61 6d 65 | 20 72 65 61 73 6f 6e 20 |the same| reason |
|00002090| 61 73 20 65 78 70 6c 61 | 69 6e 65 64 20 69 6e 20 |as expla|ined in |
|000020a0| 74 68 65 0a 70 72 65 76 | 69 6f 75 73 20 70 61 72 |the.prev|ious par|
|000020b0| 61 67 72 61 70 68 2e 29 | 0a 0a 5c 73 75 62 73 65 |agraph.)|..\subse|
|000020c0| 63 74 69 6f 6e 7b 41 72 | 67 75 6d 65 6e 74 20 50 |ction{Ar|gument P|
|000020d0| 61 73 73 69 6e 67 7d 0a | 0a 57 68 65 6e 20 6b 6e |assing}.|.When kn|
|000020e0| 6f 77 6e 20 74 6f 20 74 | 68 65 20 69 6e 74 65 72 |own to t|he inter|
|000020f0| 70 72 65 74 65 72 2c 20 | 74 68 65 20 73 63 72 69 |preter, |the scri|
|00002100| 70 74 20 6e 61 6d 65 20 | 61 6e 64 20 61 64 64 69 |pt name |and addi|
|00002110| 74 69 6f 6e 61 6c 0a 61 | 72 67 75 6d 65 6e 74 73 |tional.a|rguments|
|00002120| 20 74 68 65 72 65 61 66 | 74 65 72 20 61 72 65 20 | thereaf|ter are |
|00002130| 70 61 73 73 65 64 20 74 | 6f 20 74 68 65 20 73 63 |passed t|o the sc|
|00002140| 72 69 70 74 20 69 6e 20 | 74 68 65 20 76 61 72 69 |ript in |the vari|
|00002150| 61 62 6c 65 20 7b 5c 74 | 74 0a 73 79 73 2e 61 72 |able {\t|t.sys.ar|
|00002160| 67 76 7d 2c 20 77 68 69 | 63 68 20 69 73 20 61 20 |gv}, whi|ch is a |
|00002170| 6c 69 73 74 20 6f 66 20 | 73 74 72 69 6e 67 73 2e |list of |strings.|
|00002180| 20 20 49 74 73 20 6c 65 | 6e 67 74 68 20 69 73 20 | Its le|ngth is |
|00002190| 61 74 20 6c 65 61 73 74 | 20 6f 6e 65 3b 0a 77 68 |at least| one;.wh|
|000021a0| 65 6e 20 6e 6f 20 73 63 | 72 69 70 74 20 61 6e 64 |en no sc|ript and|
|000021b0| 20 6e 6f 20 61 72 67 75 | 6d 65 6e 74 73 20 61 72 | no argu|ments ar|
|000021c0| 65 20 67 69 76 65 6e 2c | 20 7b 5c 74 74 20 73 79 |e given,| {\tt sy|
|000021d0| 73 2e 61 72 67 76 5b 30 | 5d 7d 20 69 73 20 61 6e |s.argv[0|]} is an|
|000021e0| 0a 65 6d 70 74 79 20 73 | 74 72 69 6e 67 2e 20 20 |.empty s|tring. |
|000021f0| 57 68 65 6e 20 74 68 65 | 20 73 63 72 69 70 74 20 |When the| script |
|00002200| 6e 61 6d 65 20 69 73 20 | 67 69 76 65 6e 20 61 73 |name is |given as|
|00002210| 20 7b 5c 74 74 20 27 2d | 27 7d 20 28 6d 65 61 6e | {\tt '-|'} (mean|
|00002220| 69 6e 67 0a 73 74 61 6e | 64 61 72 64 20 69 6e 70 |ing.stan|dard inp|
|00002230| 75 74 29 2c 20 7b 5c 74 | 74 20 73 79 73 2e 61 72 |ut), {\t|t sys.ar|
|00002240| 67 76 5b 30 5d 7d 20 69 | 73 20 73 65 74 20 74 6f |gv[0]} i|s set to|
|00002250| 20 7b 5c 74 74 20 27 2d | 27 7d 2e 20 20 57 68 65 | {\tt '-|'}. Whe|
|00002260| 6e 20 7b 5c 74 74 20 2d | 63 0a 63 6f 6d 6d 61 6e |n {\tt -|c.comman|
|00002270| 64 7d 20 69 73 20 75 73 | 65 64 2c 20 7b 5c 74 74 |d} is us|ed, {\tt|
|00002280| 20 73 79 73 2e 61 72 67 | 76 5b 30 5d 7d 20 69 73 | sys.arg|v[0]} is|
|00002290| 20 73 65 74 20 74 6f 20 | 7b 5c 74 74 20 27 2d 63 | set to |{\tt '-c|
|000022a0| 27 7d 2e 20 20 4f 70 74 | 69 6f 6e 73 0a 66 6f 75 |'}. Opt|ions.fou|
|000022b0| 6e 64 20 61 66 74 65 72 | 20 7b 5c 74 74 20 2d 63 |nd after| {\tt -c|
|000022c0| 20 63 6f 6d 6d 61 6e 64 | 7d 20 61 72 65 20 6e 6f | command|} are no|
|000022d0| 74 20 63 6f 6e 73 75 6d | 65 64 20 62 79 20 74 68 |t consum|ed by th|
|000022e0| 65 20 50 79 74 68 6f 6e | 0a 69 6e 74 65 72 70 72 |e Python|.interpr|
|000022f0| 65 74 65 72 27 73 20 6f | 70 74 69 6f 6e 20 70 72 |eter's o|ption pr|
|00002300| 6f 63 65 73 73 69 6e 67 | 20 62 75 74 20 6c 65 66 |ocessing| but lef|
|00002310| 74 20 69 6e 20 7b 5c 74 | 74 20 73 79 73 2e 61 72 |t in {\t|t sys.ar|
|00002320| 67 76 7d 20 66 6f 72 20 | 74 68 65 0a 63 6f 6d 6d |gv} for |the.comm|
|00002330| 61 6e 64 20 74 6f 20 68 | 61 6e 64 6c 65 2e 0a 0a |and to h|andle...|
|00002340| 5c 73 75 62 73 65 63 74 | 69 6f 6e 7b 49 6e 74 65 |\subsect|ion{Inte|
|00002350| 72 61 63 74 69 76 65 20 | 4d 6f 64 65 7d 0a 0a 57 |ractive |Mode}..W|
|00002360| 68 65 6e 20 63 6f 6d 6d | 61 6e 64 73 20 61 72 65 |hen comm|ands are|
|00002370| 20 72 65 61 64 20 66 72 | 6f 6d 20 61 20 74 74 79 | read fr|om a tty|
|00002380| 2c 20 74 68 65 20 69 6e | 74 65 72 70 72 65 74 65 |, the in|terprete|
|00002390| 72 20 69 73 20 73 61 69 | 64 20 74 6f 20 62 65 20 |r is sai|d to be |
|000023a0| 69 6e 0a 7b 5c 65 6d 20 | 69 6e 74 65 72 61 63 74 |in.{\em |interact|
|000023b0| 69 76 65 5c 20 6d 6f 64 | 65 7d 2e 20 20 49 6e 20 |ive\ mod|e}. In |
|000023c0| 74 68 69 73 20 6d 6f 64 | 65 20 69 74 20 70 72 6f |this mod|e it pro|
|000023d0| 6d 70 74 73 20 66 6f 72 | 20 74 68 65 20 6e 65 78 |mpts for| the nex|
|000023e0| 74 20 63 6f 6d 6d 61 6e | 64 0a 77 69 74 68 20 74 |t comman|d.with t|
|000023f0| 68 65 20 7b 5c 65 6d 20 | 70 72 69 6d 61 72 79 5c |he {\em |primary\|
|00002400| 20 70 72 6f 6d 70 74 7d | 2c 20 75 73 75 61 6c 6c | prompt}|, usuall|
|00002410| 79 20 74 68 72 65 65 20 | 67 72 65 61 74 65 72 2d |y three |greater-|
|00002420| 74 68 61 6e 20 73 69 67 | 6e 73 20 28 7b 5c 74 74 |than sig|ns ({\tt|
|00002430| 0a 3e 3e 3e 7d 29 3b 20 | 66 6f 72 20 63 6f 6e 74 |.>>>}); |for cont|
|00002440| 69 6e 75 61 74 69 6f 6e | 20 6c 69 6e 65 73 20 69 |inuation| lines i|
|00002450| 74 20 70 72 6f 6d 70 74 | 73 20 77 69 74 68 20 74 |t prompt|s with t|
|00002460| 68 65 0a 7b 5c 65 6d 20 | 73 65 63 6f 6e 64 61 72 |he.{\em |secondar|
|00002470| 79 5c 20 70 72 6f 6d 70 | 74 7d 2c 0a 62 79 20 64 |y\ promp|t},.by d|
|00002480| 65 66 61 75 6c 74 20 74 | 68 72 65 65 20 64 6f 74 |efault t|hree dot|
|00002490| 73 20 28 7b 5c 74 74 20 | 2e 2e 2e 7d 29 2e 20 20 |s ({\tt |...}). |
|000024a0| 54 79 70 69 6e 67 20 61 | 6e 20 45 4f 46 20 63 68 |Typing a|n EOF ch|
|000024b0| 61 72 61 63 74 65 72 0a | 28 43 6f 6e 74 72 6f 6c |aracter.|(Control|
|000024c0| 2d 44 20 6f 6e 20 7b 5c | 55 4e 49 58 7d 2c 20 43 |-D on {\|UNIX}, C|
|000024d0| 6f 6e 74 72 6f 6c 2d 5a | 20 6f 6e 20 44 4f 53 20 |ontrol-Z| on DOS |
|000024e0| 6f 72 20 57 69 6e 64 6f | 77 73 29 0a 61 74 20 74 |or Windo|ws).at t|
|000024f0| 68 65 20 70 72 69 6d 61 | 72 79 20 70 72 6f 6d 70 |he prima|ry promp|
|00002500| 74 20 63 61 75 73 65 73 | 20 74 68 65 20 69 6e 74 |t causes| the int|
|00002510| 65 72 70 72 65 74 65 72 | 20 74 6f 20 65 78 69 74 |erpreter| to exit|
|00002520| 20 77 69 74 68 20 61 20 | 7a 65 72 6f 20 65 78 69 | with a |zero exi|
|00002530| 74 0a 73 74 61 74 75 73 | 2e 0a 0a 54 68 65 20 69 |t.status|...The i|
|00002540| 6e 74 65 72 70 72 65 74 | 65 72 20 70 72 69 6e 74 |nterpret|er print|
|00002550| 73 20 61 20 77 65 6c 63 | 6f 6d 65 20 6d 65 73 73 |s a welc|ome mess|
|00002560| 61 67 65 20 73 74 61 74 | 69 6e 67 20 69 74 73 20 |age stat|ing its |
|00002570| 76 65 72 73 69 6f 6e 20 | 6e 75 6d 62 65 72 0a 61 |version |number.a|
|00002580| 6e 64 20 61 20 63 6f 70 | 79 72 69 67 68 74 20 6e |nd a cop|yright n|
|00002590| 6f 74 69 63 65 20 62 65 | 66 6f 72 65 20 70 72 69 |otice be|fore pri|
|000025a0| 6e 74 69 6e 67 20 74 68 | 65 20 66 69 72 73 74 20 |nting th|e first |
|000025b0| 70 72 6f 6d 70 74 2c 20 | 65 2e 67 2e 3a 0a 0a 5c |prompt, |e.g.:..\|
|000025c0| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|000025d0| 61 74 69 6d 7d 0a 70 79 | 74 68 6f 6e 0a 50 79 74 |atim}.py|thon.Pyt|
|000025e0| 68 6f 6e 20 31 2e 34 20 | 28 4f 63 74 20 32 35 20 |hon 1.4 |(Oct 25 |
|000025f0| 31 39 39 36 29 20 20 5b | 47 43 43 20 32 2e 37 2e |1996) [|GCC 2.7.|
|00002600| 32 5d 0a 43 6f 70 79 72 | 69 67 68 74 20 31 39 39 |2].Copyr|ight 199|
|00002610| 31 2d 31 39 39 36 20 53 | 74 69 63 68 74 69 6e 67 |1-1996 S|tichting|
|00002620| 20 4d 61 74 68 65 6d 61 | 74 69 73 63 68 20 43 65 | Mathema|tisch Ce|
|00002630| 6e 74 72 75 6d 2c 20 41 | 6d 73 74 65 72 64 61 6d |ntrum, A|msterdam|
|00002640| 0a 3e 3e 3e 0a 5c 65 6e | 64 7b 76 65 72 62 61 74 |.>>>.\en|d{verbat|
|00002650| 69 6d 7d 5c 65 63 6f 64 | 65 0a 0a 5c 73 65 63 74 |im}\ecod|e..\sect|
|00002660| 69 6f 6e 7b 54 68 65 20 | 49 6e 74 65 72 70 72 65 |ion{The |Interpre|
|00002670| 74 65 72 20 61 6e 64 20 | 69 74 73 20 45 6e 76 69 |ter and |its Envi|
|00002680| 72 6f 6e 6d 65 6e 74 7d | 0a 0a 5c 73 75 62 73 65 |ronment}|..\subse|
|00002690| 63 74 69 6f 6e 7b 45 72 | 72 6f 72 20 48 61 6e 64 |ction{Er|ror Hand|
|000026a0| 6c 69 6e 67 7d 0a 0a 57 | 68 65 6e 20 61 6e 20 65 |ling}..W|hen an e|
|000026b0| 72 72 6f 72 20 6f 63 63 | 75 72 73 2c 20 74 68 65 |rror occ|urs, the|
|000026c0| 20 69 6e 74 65 72 70 72 | 65 74 65 72 20 70 72 69 | interpr|eter pri|
|000026d0| 6e 74 73 20 61 6e 20 65 | 72 72 6f 72 0a 6d 65 73 |nts an e|rror.mes|
|000026e0| 73 61 67 65 20 61 6e 64 | 20 61 20 73 74 61 63 6b |sage and| a stack|
|000026f0| 20 74 72 61 63 65 2e 20 | 20 49 6e 20 69 6e 74 65 | trace. | In inte|
|00002700| 72 61 63 74 69 76 65 20 | 6d 6f 64 65 2c 20 69 74 |ractive |mode, it|
|00002710| 20 74 68 65 6e 20 72 65 | 74 75 72 6e 73 20 74 6f | then re|turns to|
|00002720| 0a 74 68 65 20 70 72 69 | 6d 61 72 79 20 70 72 6f |.the pri|mary pro|
|00002730| 6d 70 74 3b 20 77 68 65 | 6e 20 69 6e 70 75 74 20 |mpt; whe|n input |
|00002740| 63 61 6d 65 20 66 72 6f | 6d 20 61 20 66 69 6c 65 |came fro|m a file|
|00002750| 2c 20 69 74 20 65 78 69 | 74 73 20 77 69 74 68 20 |, it exi|ts with |
|00002760| 61 0a 6e 6f 6e 7a 65 72 | 6f 20 65 78 69 74 20 73 |a.nonzer|o exit s|
|00002770| 74 61 74 75 73 20 61 66 | 74 65 72 20 70 72 69 6e |tatus af|ter prin|
|00002780| 74 69 6e 67 0a 74 68 65 | 20 73 74 61 63 6b 20 74 |ting.the| stack t|
|00002790| 72 61 63 65 2e 20 20 28 | 45 78 63 65 70 74 69 6f |race. (|Exceptio|
|000027a0| 6e 73 20 68 61 6e 64 6c | 65 64 20 62 79 20 61 6e |ns handl|ed by an|
|000027b0| 20 7b 5c 74 74 20 65 78 | 63 65 70 74 7d 20 63 6c | {\tt ex|cept} cl|
|000027c0| 61 75 73 65 20 69 6e 20 | 61 0a 7b 5c 74 74 20 74 |ause in |a.{\tt t|
|000027d0| 72 79 7d 20 73 74 61 74 | 65 6d 65 6e 74 20 61 72 |ry} stat|ement ar|
|000027e0| 65 20 6e 6f 74 20 65 72 | 72 6f 72 73 20 69 6e 20 |e not er|rors in |
|000027f0| 74 68 69 73 20 63 6f 6e | 74 65 78 74 2e 29 20 20 |this con|text.) |
|00002800| 53 6f 6d 65 20 65 72 72 | 6f 72 73 20 61 72 65 0a |Some err|ors are.|
|00002810| 75 6e 63 6f 6e 64 69 74 | 69 6f 6e 61 6c 6c 79 20 |uncondit|ionally |
|00002820| 66 61 74 61 6c 20 61 6e | 64 20 63 61 75 73 65 20 |fatal an|d cause |
|00002830| 61 6e 20 65 78 69 74 20 | 77 69 74 68 20 61 20 6e |an exit |with a n|
|00002840| 6f 6e 7a 65 72 6f 20 65 | 78 69 74 3b 20 74 68 69 |onzero e|xit; thi|
|00002850| 73 0a 61 70 70 6c 69 65 | 73 20 74 6f 20 69 6e 74 |s.applie|s to int|
|00002860| 65 72 6e 61 6c 20 69 6e | 63 6f 6e 73 69 73 74 65 |ernal in|consiste|
|00002870| 6e 63 69 65 73 20 61 6e | 64 20 73 6f 6d 65 20 63 |ncies an|d some c|
|00002880| 61 73 65 73 20 6f 66 20 | 72 75 6e 6e 69 6e 67 20 |ases of |running |
|00002890| 6f 75 74 20 6f 66 0a 6d | 65 6d 6f 72 79 2e 20 20 |out of.m|emory. |
|000028a0| 41 6c 6c 20 65 72 72 6f | 72 20 6d 65 73 73 61 67 |All erro|r messag|
|000028b0| 65 73 20 61 72 65 20 77 | 72 69 74 74 65 6e 20 74 |es are w|ritten t|
|000028c0| 6f 20 74 68 65 20 73 74 | 61 6e 64 61 72 64 20 65 |o the st|andard e|
|000028d0| 72 72 6f 72 20 73 74 72 | 65 61 6d 3b 0a 6e 6f 72 |rror str|eam;.nor|
|000028e0| 6d 61 6c 20 6f 75 74 70 | 75 74 20 66 72 6f 6d 20 |mal outp|ut from |
|000028f0| 74 68 65 20 65 78 65 63 | 75 74 65 64 20 63 6f 6d |the exec|uted com|
|00002900| 6d 61 6e 64 73 20 69 73 | 20 77 72 69 74 74 65 6e |mands is| written|
|00002910| 20 74 6f 20 73 74 61 6e | 64 61 72 64 0a 6f 75 74 | to stan|dard.out|
|00002920| 70 75 74 2e 0a 0a 54 79 | 70 69 6e 67 20 74 68 65 |put...Ty|ping the|
|00002930| 20 69 6e 74 65 72 72 75 | 70 74 20 63 68 61 72 61 | interru|pt chara|
|00002940| 63 74 65 72 20 28 75 73 | 75 61 6c 6c 79 20 43 6f |cter (us|ually Co|
|00002950| 6e 74 72 6f 6c 2d 43 20 | 6f 72 20 44 45 4c 29 20 |ntrol-C |or DEL) |
|00002960| 74 6f 20 74 68 65 0a 70 | 72 69 6d 61 72 79 20 6f |to the.p|rimary o|
|00002970| 72 20 73 65 63 6f 6e 64 | 61 72 79 20 70 72 6f 6d |r second|ary prom|
|00002980| 70 74 20 63 61 6e 63 65 | 6c 73 20 74 68 65 20 69 |pt cance|ls the i|
|00002990| 6e 70 75 74 20 61 6e 64 | 20 72 65 74 75 72 6e 73 |nput and| returns|
|000029a0| 20 74 6f 20 74 68 65 0a | 70 72 69 6d 61 72 79 20 | to the.|primary |
|000029b0| 70 72 6f 6d 70 74 2e 25 | 0a 5c 66 6f 6f 74 6e 6f |prompt.%|.\footno|
|000029c0| 74 65 7b 0a 20 20 20 20 | 20 20 20 20 41 20 70 72 |te{. | A pr|
|000029d0| 6f 62 6c 65 6d 20 77 69 | 74 68 20 74 68 65 20 47 |oblem wi|th the G|
|000029e0| 4e 55 20 52 65 61 64 6c | 69 6e 65 20 70 61 63 6b |NU Readl|ine pack|
|000029f0| 61 67 65 20 6d 61 79 20 | 70 72 65 76 65 6e 74 20 |age may |prevent |
|00002a00| 74 68 69 73 2e 0a 7d 0a | 54 79 70 69 6e 67 20 61 |this..}.|Typing a|
|00002a10| 6e 20 69 6e 74 65 72 72 | 75 70 74 20 77 68 69 6c |n interr|upt whil|
|00002a20| 65 20 61 20 63 6f 6d 6d | 61 6e 64 20 69 73 20 65 |e a comm|and is e|
|00002a30| 78 65 63 75 74 69 6e 67 | 20 72 61 69 73 65 73 20 |xecuting| raises |
|00002a40| 74 68 65 20 7b 5c 74 74 | 0a 4b 65 79 62 6f 61 72 |the {\tt|.Keyboar|
|00002a50| 64 49 6e 74 65 72 72 75 | 70 74 7d 20 65 78 63 65 |dInterru|pt} exce|
|00002a60| 70 74 69 6f 6e 2c 20 77 | 68 69 63 68 20 6d 61 79 |ption, w|hich may|
|00002a70| 20 62 65 20 68 61 6e 64 | 6c 65 64 20 62 79 20 61 | be hand|led by a|
|00002a80| 20 7b 5c 74 74 20 74 72 | 79 7d 0a 73 74 61 74 65 | {\tt tr|y}.state|
|00002a90| 6d 65 6e 74 2e 0a 0a 5c | 73 75 62 73 65 63 74 69 |ment...\|subsecti|
|00002aa0| 6f 6e 7b 54 68 65 20 4d | 6f 64 75 6c 65 20 53 65 |on{The M|odule Se|
|00002ab0| 61 72 63 68 20 50 61 74 | 68 7d 0a 0a 57 68 65 6e |arch Pat|h}..When|
|00002ac0| 20 61 20 6d 6f 64 75 6c | 65 20 6e 61 6d 65 64 20 | a modul|e named |
|00002ad0| 7b 5c 74 74 20 73 70 61 | 6d 7d 20 69 73 20 69 6d |{\tt spa|m} is im|
|00002ae0| 70 6f 72 74 65 64 2c 20 | 74 68 65 20 69 6e 74 65 |ported, |the inte|
|00002af0| 72 70 72 65 74 65 72 20 | 73 65 61 72 63 68 65 73 |rpreter |searches|
|00002b00| 0a 66 6f 72 20 61 20 66 | 69 6c 65 20 6e 61 6d 65 |.for a f|ile name|
|00002b10| 64 20 7b 5c 74 74 20 73 | 70 61 6d 2e 70 79 7d 20 |d {\tt s|pam.py} |
|00002b20| 69 6e 20 74 68 65 20 63 | 75 72 72 65 6e 74 20 64 |in the c|urrent d|
|00002b30| 69 72 65 63 74 6f 72 79 | 2c 0a 61 6e 64 20 74 68 |irectory|,.and th|
|00002b40| 65 6e 20 69 6e 20 74 68 | 65 20 6c 69 73 74 20 6f |en in th|e list o|
|00002b50| 66 20 64 69 72 65 63 74 | 6f 72 69 65 73 20 73 70 |f direct|ories sp|
|00002b60| 65 63 69 66 69 65 64 20 | 62 79 0a 74 68 65 20 65 |ecified |by.the e|
|00002b70| 6e 76 69 72 6f 6e 6d 65 | 6e 74 20 76 61 72 69 61 |nvironme|nt varia|
|00002b80| 62 6c 65 20 7b 5c 74 74 | 20 50 59 54 48 4f 4e 50 |ble {\tt| PYTHONP|
|00002b90| 41 54 48 7d 2e 20 20 54 | 68 69 73 20 68 61 73 20 |ATH}. T|his has |
|00002ba0| 74 68 65 20 73 61 6d 65 | 20 73 79 6e 74 61 78 20 |the same| syntax |
|00002bb0| 61 73 0a 74 68 65 20 7b | 5c 55 4e 49 58 7d 20 73 |as.the {|\UNIX} s|
|00002bc0| 68 65 6c 6c 20 76 61 72 | 69 61 62 6c 65 20 7b 5c |hell var|iable {\|
|00002bd0| 74 74 20 50 41 54 48 7d | 2c 20 69 2e 65 2e 2c 20 |tt PATH}|, i.e., |
|00002be0| 61 20 6c 69 73 74 20 6f | 66 20 63 6f 6c 6f 6e 2d |a list o|f colon-|
|00002bf0| 73 65 70 61 72 61 74 65 | 64 0a 64 69 72 65 63 74 |separate|d.direct|
|00002c00| 6f 72 79 20 6e 61 6d 65 | 73 2e 20 20 57 68 65 6e |ory name|s. When|
|00002c10| 20 7b 5c 74 74 20 50 59 | 54 48 4f 4e 50 41 54 48 | {\tt PY|THONPATH|
|00002c20| 7d 20 69 73 20 6e 6f 74 | 20 73 65 74 2c 20 6f 72 |} is not| set, or|
|00002c30| 20 77 68 65 6e 20 74 68 | 65 20 66 69 6c 65 0a 69 | when th|e file.i|
|00002c40| 73 20 6e 6f 74 20 66 6f | 75 6e 64 20 74 68 65 72 |s not fo|und ther|
|00002c50| 65 2c 20 74 68 65 20 73 | 65 61 72 63 68 20 63 6f |e, the s|earch co|
|00002c60| 6e 74 69 6e 75 65 73 20 | 69 6e 20 61 6e 20 69 6e |ntinues |in an in|
|00002c70| 73 74 61 6c 6c 61 74 69 | 6f 6e 2d 64 65 70 65 6e |stallati|on-depen|
|00002c80| 64 65 6e 74 0a 64 65 66 | 61 75 6c 74 20 70 61 74 |dent.def|ault pat|
|00002c90| 68 2c 20 75 73 75 61 6c | 6c 79 20 7b 5c 74 74 20 |h, usual|ly {\tt |
|00002ca0| 2e 3a 2f 75 73 72 2f 6c | 6f 63 61 6c 2f 6c 69 62 |.:/usr/l|ocal/lib|
|00002cb0| 2f 70 79 74 68 6f 6e 7d | 2e 0a 0a 41 63 74 75 61 |/python}|...Actua|
|00002cc0| 6c 6c 79 2c 20 6d 6f 64 | 75 6c 65 73 20 61 72 65 |lly, mod|ules are|
|00002cd0| 20 73 65 61 72 63 68 65 | 64 20 69 6e 20 74 68 65 | searche|d in the|
|00002ce0| 20 6c 69 73 74 20 6f 66 | 20 64 69 72 65 63 74 6f | list of| directo|
|00002cf0| 72 69 65 73 20 67 69 76 | 65 6e 20 62 79 20 74 68 |ries giv|en by th|
|00002d00| 65 20 0a 76 61 72 69 61 | 62 6c 65 20 7b 5c 74 74 |e .varia|ble {\tt|
|00002d10| 20 73 79 73 2e 70 61 74 | 68 7d 20 77 68 69 63 68 | sys.pat|h} which|
|00002d20| 20 69 73 20 69 6e 69 74 | 69 61 6c 69 7a 65 64 20 | is init|ialized |
|00002d30| 66 72 6f 6d 20 74 68 65 | 20 64 69 72 65 63 74 6f |from the| directo|
|00002d40| 72 79 20 0a 63 6f 6e 74 | 61 69 6e 69 6e 67 20 74 |ry .cont|aining t|
|00002d50| 68 65 20 69 6e 70 75 74 | 20 73 63 72 69 70 74 20 |he input| script |
|00002d60| 28 6f 72 20 74 68 65 20 | 63 75 72 72 65 6e 74 20 |(or the |current |
|00002d70| 64 69 72 65 63 74 6f 72 | 79 29 2c 20 7b 5c 74 74 |director|y), {\tt|
|00002d80| 20 0a 50 59 54 48 4f 4e | 50 41 54 48 7d 20 61 6e | .PYTHON|PATH} an|
|00002d90| 64 20 74 68 65 20 69 6e | 73 74 61 6c 6c 61 74 69 |d the in|stallati|
|00002da0| 6f 6e 2d 64 65 70 65 6e | 64 65 6e 74 20 64 65 66 |on-depen|dent def|
|00002db0| 61 75 6c 74 2e 20 20 54 | 68 69 73 20 61 6c 6c 6f |ault. T|his allo|
|00002dc0| 77 73 20 0a 50 79 74 68 | 6f 6e 20 70 72 6f 67 72 |ws .Pyth|on progr|
|00002dd0| 61 6d 73 20 74 68 61 74 | 20 6b 6e 6f 77 20 77 68 |ams that| know wh|
|00002de0| 61 74 20 74 68 65 79 27 | 72 65 20 64 6f 69 6e 67 |at they'|re doing|
|00002df0| 20 74 6f 20 6d 6f 64 69 | 66 79 20 6f 72 20 72 65 | to modi|fy or re|
|00002e00| 70 6c 61 63 65 20 74 68 | 65 20 0a 6d 6f 64 75 6c |place th|e .modul|
|00002e10| 65 20 73 65 61 72 63 68 | 20 70 61 74 68 2e 20 20 |e search| path. |
|00002e20| 53 65 65 20 74 68 65 20 | 73 65 63 74 69 6f 6e 20 |See the |section |
|00002e30| 6f 6e 20 53 74 61 6e 64 | 61 72 64 20 4d 6f 64 75 |on Stand|ard Modu|
|00002e40| 6c 65 73 20 6c 61 74 65 | 72 2e 0a 0a 5c 73 75 62 |les late|r...\sub|
|00002e50| 73 65 63 74 69 6f 6e 7b | 60 60 43 6f 6d 70 69 6c |section{|``Compil|
|00002e60| 65 64 27 27 20 50 79 74 | 68 6f 6e 20 66 69 6c 65 |ed'' Pyt|hon file|
|00002e70| 73 7d 0a 0a 41 73 20 61 | 6e 20 69 6d 70 6f 72 74 |s}..As a|n import|
|00002e80| 61 6e 74 20 73 70 65 65 | 64 2d 75 70 20 6f 66 20 |ant spee|d-up of |
|00002e90| 74 68 65 20 73 74 61 72 | 74 2d 75 70 20 74 69 6d |the star|t-up tim|
|00002ea0| 65 20 66 6f 72 20 73 68 | 6f 72 74 20 70 72 6f 67 |e for sh|ort prog|
|00002eb0| 72 61 6d 73 20 74 68 61 | 74 0a 75 73 65 20 61 20 |rams tha|t.use a |
|00002ec0| 6c 6f 74 20 6f 66 20 73 | 74 61 6e 64 61 72 64 20 |lot of s|tandard |
|00002ed0| 6d 6f 64 75 6c 65 73 2c | 20 69 66 20 61 20 66 69 |modules,| if a fi|
|00002ee0| 6c 65 20 63 61 6c 6c 65 | 64 20 7b 5c 74 74 20 73 |le calle|d {\tt s|
|00002ef0| 70 61 6d 2e 70 79 63 7d | 20 65 78 69 73 74 73 0a |pam.pyc}| exists.|
|00002f00| 69 6e 20 74 68 65 20 64 | 69 72 65 63 74 6f 72 79 |in the d|irectory|
|00002f10| 20 77 68 65 72 65 20 7b | 5c 74 74 20 73 70 61 6d | where {|\tt spam|
|00002f20| 2e 70 79 7d 20 69 73 20 | 66 6f 75 6e 64 2c 20 74 |.py} is |found, t|
|00002f30| 68 69 73 20 69 73 20 61 | 73 73 75 6d 65 64 20 74 |his is a|ssumed t|
|00002f40| 6f 0a 63 6f 6e 74 61 69 | 6e 20 61 6e 20 61 6c 72 |o.contai|n an alr|
|00002f50| 65 61 64 79 2d 60 60 63 | 6f 6d 70 69 6c 65 64 27 |eady-``c|ompiled'|
|00002f60| 27 20 76 65 72 73 69 6f | 6e 20 6f 66 20 74 68 65 |' versio|n of the|
|00002f70| 20 6d 6f 64 75 6c 65 20 | 7b 5c 74 74 20 73 70 61 | module |{\tt spa|
|00002f80| 6d 7d 2e 20 20 54 68 65 | 0a 6d 6f 64 69 66 69 63 |m}. The|.modific|
|00002f90| 61 74 69 6f 6e 20 74 69 | 6d 65 20 6f 66 20 74 68 |ation ti|me of th|
|00002fa0| 65 20 76 65 72 73 69 6f | 6e 20 6f 66 20 7b 5c 74 |e versio|n of {\t|
|00002fb0| 74 20 73 70 61 6d 2e 70 | 79 7d 20 75 73 65 64 20 |t spam.p|y} used |
|00002fc0| 74 6f 20 63 72 65 61 74 | 65 20 7b 5c 74 74 0a 73 |to creat|e {\tt.s|
|00002fd0| 70 61 6d 2e 70 79 63 7d | 20 69 73 20 72 65 63 6f |pam.pyc}| is reco|
|00002fe0| 72 64 65 64 20 69 6e 20 | 7b 5c 74 74 20 73 70 61 |rded in |{\tt spa|
|00002ff0| 6d 2e 70 79 63 7d 2c 20 | 61 6e 64 20 74 68 65 20 |m.pyc}, |and the |
|00003000| 66 69 6c 65 20 69 73 20 | 69 67 6e 6f 72 65 64 20 |file is |ignored |
|00003010| 69 66 0a 74 68 65 73 65 | 20 64 6f 6e 27 74 20 6d |if.these| don't m|
|00003020| 61 74 63 68 2e 0a 0a 4e | 6f 72 6d 61 6c 6c 79 2c |atch...N|ormally,|
|00003030| 20 79 6f 75 20 64 6f 6e | 27 74 20 6e 65 65 64 20 | you don|'t need |
|00003040| 74 6f 20 64 6f 20 61 6e | 79 74 68 69 6e 67 20 74 |to do an|ything t|
|00003050| 6f 20 63 72 65 61 74 65 | 20 74 68 65 20 7b 5c 74 |o create| the {\t|
|00003060| 74 20 73 70 61 6d 2e 70 | 79 63 7d 20 66 69 6c 65 |t spam.p|yc} file|
|00003070| 2e 0a 57 68 65 6e 65 76 | 65 72 20 7b 5c 74 74 20 |..Whenev|er {\tt |
|00003080| 73 70 61 6d 2e 70 79 7d | 20 69 73 20 73 75 63 63 |spam.py}| is succ|
|00003090| 65 73 73 66 75 6c 6c 79 | 20 63 6f 6d 70 69 6c 65 |essfully| compile|
|000030a0| 64 2c 20 61 6e 20 61 74 | 74 65 6d 70 74 20 69 73 |d, an at|tempt is|
|000030b0| 20 6d 61 64 65 20 74 6f | 0a 77 72 69 74 65 20 74 | made to|.write t|
|000030c0| 68 65 20 63 6f 6d 70 69 | 6c 65 64 20 76 65 72 73 |he compi|led vers|
|000030d0| 69 6f 6e 20 74 6f 20 7b | 5c 74 74 20 73 70 61 6d |ion to {|\tt spam|
|000030e0| 2e 70 79 63 7d 2e 20 20 | 49 74 20 69 73 20 6e 6f |.pyc}. |It is no|
|000030f0| 74 20 61 6e 20 65 72 72 | 6f 72 20 69 66 0a 74 68 |t an err|or if.th|
|00003100| 69 73 20 61 74 74 65 6d | 70 74 20 66 61 69 6c 73 |is attem|pt fails|
|00003110| 3b 20 69 66 20 66 6f 72 | 20 61 6e 79 20 72 65 61 |; if for| any rea|
|00003120| 73 6f 6e 20 74 68 65 20 | 66 69 6c 65 20 69 73 20 |son the |file is |
|00003130| 6e 6f 74 20 77 72 69 74 | 74 65 6e 0a 63 6f 6d 70 |not writ|ten.comp|
|00003140| 6c 65 74 65 6c 79 2c 20 | 74 68 65 20 72 65 73 75 |letely, |the resu|
|00003150| 6c 74 69 6e 67 20 7b 5c | 74 74 20 73 70 61 6d 2e |lting {\|tt spam.|
|00003160| 70 79 63 7d 20 66 69 6c | 65 20 77 69 6c 6c 20 62 |pyc} fil|e will b|
|00003170| 65 20 72 65 63 6f 67 6e | 69 7a 65 64 20 61 73 0a |e recogn|ized as.|
|00003180| 69 6e 76 61 6c 69 64 20 | 61 6e 64 20 74 68 75 73 |invalid |and thus|
|00003190| 20 69 67 6e 6f 72 65 64 | 20 6c 61 74 65 72 2e 20 | ignored| later. |
|000031a0| 20 54 68 65 20 63 6f 6e | 74 65 6e 74 73 20 6f 66 | The con|tents of|
|000031b0| 20 74 68 65 20 7b 5c 74 | 74 20 73 70 61 6d 2e 70 | the {\t|t spam.p|
|000031c0| 79 63 7d 0a 66 69 6c 65 | 20 69 73 20 70 6c 61 74 |yc}.file| is plat|
|000031d0| 66 6f 72 6d 20 69 6e 64 | 65 70 65 6e 64 65 6e 74 |form ind|ependent|
|000031e0| 2c 20 73 6f 20 61 20 50 | 79 74 68 6f 6e 20 6d 6f |, so a P|ython mo|
|000031f0| 64 75 6c 65 20 64 69 72 | 65 63 74 6f 72 79 20 63 |dule dir|ectory c|
|00003200| 61 6e 20 62 65 0a 73 68 | 61 72 65 64 20 62 79 20 |an be.sh|ared by |
|00003210| 6d 61 63 68 69 6e 65 73 | 20 6f 66 20 64 69 66 66 |machines| of diff|
|00003220| 65 72 65 6e 74 20 61 72 | 63 68 69 74 65 63 74 75 |erent ar|chitectu|
|00003230| 72 65 73 2e 20 20 28 54 | 69 70 20 66 6f 72 20 65 |res. (T|ip for e|
|00003240| 78 70 65 72 74 73 3a 0a | 74 68 65 20 6d 6f 64 75 |xperts:.|the modu|
|00003250| 6c 65 20 7b 5c 74 74 20 | 63 6f 6d 70 69 6c 65 61 |le {\tt |compilea|
|00003260| 6c 6c 7d 20 63 72 65 61 | 74 65 73 20 7b 5c 74 74 |ll} crea|tes {\tt|
|00003270| 20 2e 70 79 63 7d 20 66 | 69 6c 65 73 20 66 6f 72 | .pyc} f|iles for|
|00003280| 20 61 6c 6c 20 6d 6f 64 | 75 6c 65 73 2e 29 0a 0a | all mod|ules.)..|
|00003290| 5c 73 75 62 73 65 63 74 | 69 6f 6e 7b 45 78 65 63 |\subsect|ion{Exec|
|000032a0| 75 74 61 62 6c 65 20 50 | 79 74 68 6f 6e 20 73 63 |utable P|ython sc|
|000032b0| 72 69 70 74 73 7d 0a 0a | 4f 6e 20 42 53 44 27 69 |ripts}..|On BSD'i|
|000032c0| 73 68 20 7b 5c 55 4e 49 | 58 7d 20 73 79 73 74 65 |sh {\UNI|X} syste|
|000032d0| 6d 73 2c 20 50 79 74 68 | 6f 6e 20 73 63 72 69 70 |ms, Pyth|on scrip|
|000032e0| 74 73 20 63 61 6e 20 62 | 65 20 6d 61 64 65 20 64 |ts can b|e made d|
|000032f0| 69 72 65 63 74 6c 79 0a | 65 78 65 63 75 74 61 62 |irectly.|executab|
|00003300| 6c 65 2c 20 6c 69 6b 65 | 20 73 68 65 6c 6c 20 73 |le, like| shell s|
|00003310| 63 72 69 70 74 73 2c 20 | 62 79 20 70 75 74 74 69 |cripts, |by putti|
|00003320| 6e 67 20 74 68 65 20 6c | 69 6e 65 0a 0a 5c 62 63 |ng the l|ine..\bc|
|00003330| 6f 64 65 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |ode\begi|n{verbat|
|00003340| 69 6d 7d 0a 23 21 20 2f | 75 73 72 2f 6c 6f 63 61 |im}.#! /|usr/loca|
|00003350| 6c 2f 62 69 6e 2f 70 79 | 74 68 6f 6e 0a 5c 65 6e |l/bin/py|thon.\en|
|00003360| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00003370| 65 0a 25 0a 28 61 73 73 | 75 6d 69 6e 67 20 74 68 |e.%.(ass|uming th|
|00003380| 61 74 27 73 20 74 68 65 | 20 6e 61 6d 65 20 6f 66 |at's the| name of|
|00003390| 20 74 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 | the int|erpreter|
|000033a0| 29 20 61 74 20 74 68 65 | 20 62 65 67 69 6e 6e 69 |) at the| beginni|
|000033b0| 6e 67 20 6f 66 20 74 68 | 65 0a 73 63 72 69 70 74 |ng of th|e.script|
|000033c0| 20 61 6e 64 20 67 69 76 | 69 6e 67 20 74 68 65 20 | and giv|ing the |
|000033d0| 66 69 6c 65 20 61 6e 20 | 65 78 65 63 75 74 61 62 |file an |executab|
|000033e0| 6c 65 20 6d 6f 64 65 2e | 20 20 54 68 65 20 7b 5c |le mode.| The {\|
|000033f0| 74 74 20 5c 23 21 7d 20 | 6d 75 73 74 20 62 65 0a |tt \#!} |must be.|
|00003400| 74 68 65 20 66 69 72 73 | 74 20 74 77 6f 20 63 68 |the firs|t two ch|
|00003410| 61 72 61 63 74 65 72 73 | 20 6f 66 20 74 68 65 20 |aracters| of the |
|00003420| 66 69 6c 65 2e 0a 0a 5c | 73 75 62 73 65 63 74 69 |file...\|subsecti|
|00003430| 6f 6e 7b 54 68 65 20 49 | 6e 74 65 72 61 63 74 69 |on{The I|nteracti|
|00003440| 76 65 20 53 74 61 72 74 | 75 70 20 46 69 6c 65 7d |ve Start|up File}|
|00003450| 0a 0a 57 68 65 6e 20 79 | 6f 75 20 75 73 65 20 50 |..When y|ou use P|
|00003460| 79 74 68 6f 6e 20 69 6e | 74 65 72 61 63 74 69 76 |ython in|teractiv|
|00003470| 65 6c 79 2c 20 69 74 20 | 69 73 20 66 72 65 71 75 |ely, it |is frequ|
|00003480| 65 6e 74 6c 79 20 68 61 | 6e 64 79 20 74 6f 20 68 |ently ha|ndy to h|
|00003490| 61 76 65 20 73 6f 6d 65 | 0a 73 74 61 6e 64 61 72 |ave some|.standar|
|000034a0| 64 20 63 6f 6d 6d 61 6e | 64 73 20 65 78 65 63 75 |d comman|ds execu|
|000034b0| 74 65 64 20 65 76 65 72 | 79 20 74 69 6d 65 20 74 |ted ever|y time t|
|000034c0| 68 65 20 69 6e 74 65 72 | 70 72 65 74 65 72 20 69 |he inter|preter i|
|000034d0| 73 20 73 74 61 72 74 65 | 64 2e 20 20 59 6f 75 0a |s starte|d. You.|
|000034e0| 63 61 6e 20 64 6f 20 74 | 68 69 73 20 62 79 20 73 |can do t|his by s|
|000034f0| 65 74 74 69 6e 67 20 61 | 6e 20 65 6e 76 69 72 6f |etting a|n enviro|
|00003500| 6e 6d 65 6e 74 20 76 61 | 72 69 61 62 6c 65 20 6e |nment va|riable n|
|00003510| 61 6d 65 64 20 7b 5c 74 | 74 0a 50 59 54 48 4f 4e |amed {\t|t.PYTHON|
|00003520| 53 54 41 52 54 55 50 7d | 20 74 6f 20 74 68 65 20 |STARTUP}| to the |
|00003530| 6e 61 6d 65 20 6f 66 20 | 61 20 66 69 6c 65 20 63 |name of |a file c|
|00003540| 6f 6e 74 61 69 6e 69 6e | 67 20 79 6f 75 72 20 73 |ontainin|g your s|
|00003550| 74 61 72 74 2d 75 70 0a | 63 6f 6d 6d 61 6e 64 73 |tart-up.|commands|
|00003560| 2e 20 20 54 68 69 73 20 | 69 73 20 73 69 6d 69 6c |. This |is simil|
|00003570| 61 72 20 74 6f 20 74 68 | 65 20 7b 5c 74 74 20 2e |ar to th|e {\tt .|
|00003580| 70 72 6f 66 69 6c 65 7d | 20 66 65 61 74 75 72 65 |profile}| feature|
|00003590| 20 6f 66 20 74 68 65 20 | 55 4e 49 58 0a 73 68 65 | of the |UNIX.she|
|000035a0| 6c 6c 73 2e 0a 0a 54 68 | 69 73 20 66 69 6c 65 20 |lls...Th|is file |
|000035b0| 69 73 20 6f 6e 6c 79 20 | 72 65 61 64 20 69 6e 20 |is only |read in |
|000035c0| 69 6e 74 65 72 61 63 74 | 69 76 65 20 73 65 73 73 |interact|ive sess|
|000035d0| 69 6f 6e 73 2c 20 6e 6f | 74 20 77 68 65 6e 20 50 |ions, no|t when P|
|000035e0| 79 74 68 6f 6e 20 72 65 | 61 64 73 0a 63 6f 6d 6d |ython re|ads.comm|
|000035f0| 61 6e 64 73 20 66 72 6f | 6d 20 61 20 73 63 72 69 |ands fro|m a scri|
|00003600| 70 74 2c 20 61 6e 64 20 | 6e 6f 74 20 77 68 65 6e |pt, and |not when|
|00003610| 20 7b 5c 74 74 20 2f 64 | 65 76 2f 74 74 79 7d 20 | {\tt /d|ev/tty} |
|00003620| 69 73 20 67 69 76 65 6e | 20 61 73 20 74 68 65 0a |is given| as the.|
|00003630| 65 78 70 6c 69 63 69 74 | 20 73 6f 75 72 63 65 20 |explicit| source |
|00003640| 6f 66 20 63 6f 6d 6d 61 | 6e 64 73 20 28 77 68 69 |of comma|nds (whi|
|00003650| 63 68 20 6f 74 68 65 72 | 77 69 73 65 20 62 65 68 |ch other|wise beh|
|00003660| 61 76 65 73 20 6c 69 6b | 65 20 61 6e 0a 69 6e 74 |aves lik|e an.int|
|00003670| 65 72 61 63 74 69 76 65 | 20 73 65 73 73 69 6f 6e |eractive| session|
|00003680| 29 2e 20 20 49 74 20 69 | 73 20 65 78 65 63 75 74 |). It i|s execut|
|00003690| 65 64 20 69 6e 20 74 68 | 65 20 73 61 6d 65 20 6e |ed in th|e same n|
|000036a0| 61 6d 65 20 73 70 61 63 | 65 20 77 68 65 72 65 0a |ame spac|e where.|
|000036b0| 69 6e 74 65 72 61 63 74 | 69 76 65 20 63 6f 6d 6d |interact|ive comm|
|000036c0| 61 6e 64 73 20 61 72 65 | 20 65 78 65 63 75 74 65 |ands are| execute|
|000036d0| 64 2c 20 73 6f 20 74 68 | 61 74 20 6f 62 6a 65 63 |d, so th|at objec|
|000036e0| 74 73 20 74 68 61 74 20 | 69 74 20 64 65 66 69 6e |ts that |it defin|
|000036f0| 65 73 20 6f 72 0a 69 6d | 70 6f 72 74 73 20 63 61 |es or.im|ports ca|
|00003700| 6e 20 62 65 20 75 73 65 | 64 20 77 69 74 68 6f 75 |n be use|d withou|
|00003710| 74 20 71 75 61 6c 69 66 | 69 63 61 74 69 6f 6e 20 |t qualif|ication |
|00003720| 69 6e 20 74 68 65 20 69 | 6e 74 65 72 61 63 74 69 |in the i|nteracti|
|00003730| 76 65 20 73 65 73 73 69 | 6f 6e 2e 0a 59 6f 75 20 |ve sessi|on..You |
|00003740| 63 61 6e 20 61 6c 73 6f | 20 63 68 61 6e 67 65 20 |can also| change |
|00003750| 74 68 65 20 70 72 6f 6d | 70 74 73 20 7b 5c 74 74 |the prom|pts {\tt|
|00003760| 20 73 79 73 2e 70 73 31 | 7d 20 61 6e 64 20 7b 5c | sys.ps1|} and {\|
|00003770| 74 74 20 73 79 73 2e 70 | 73 32 7d 20 69 6e 0a 74 |tt sys.p|s2} in.t|
|00003780| 68 69 73 20 66 69 6c 65 | 2e 0a 0a 49 66 20 79 6f |his file|...If yo|
|00003790| 75 20 77 61 6e 74 20 74 | 6f 20 72 65 61 64 20 61 |u want t|o read a|
|000037a0| 6e 20 61 64 64 69 74 69 | 6f 6e 61 6c 20 73 74 61 |n additi|onal sta|
|000037b0| 72 74 2d 75 70 20 66 69 | 6c 65 20 66 72 6f 6d 20 |rt-up fi|le from |
|000037c0| 74 68 65 20 63 75 72 72 | 65 6e 74 0a 64 69 72 65 |the curr|ent.dire|
|000037d0| 63 74 6f 72 79 2c 20 79 | 6f 75 20 63 61 6e 20 70 |ctory, y|ou can p|
|000037e0| 72 6f 67 72 61 6d 20 74 | 68 69 73 20 69 6e 20 74 |rogram t|his in t|
|000037f0| 68 65 20 67 6c 6f 62 61 | 6c 20 73 74 61 72 74 2d |he globa|l start-|
|00003800| 75 70 20 66 69 6c 65 2c | 20 65 2e 67 2e 0a 5c 76 |up file,| e.g..\v|
|00003810| 65 72 62 5c 65 78 65 63 | 66 69 6c 65 28 27 2e 70 |erb\exec|file('.p|
|00003820| 79 74 68 6f 6e 72 63 27 | 29 5c 2e 20 20 49 66 20 |ythonrc'|)\. If |
|00003830| 79 6f 75 20 77 61 6e 74 | 20 74 6f 20 75 73 65 20 |you want| to use |
|00003840| 74 68 65 20 73 74 61 72 | 74 75 70 20 66 69 6c 65 |the star|tup file|
|00003850| 0a 69 6e 20 61 20 73 63 | 72 69 70 74 2c 20 79 6f |.in a sc|ript, yo|
|00003860| 75 20 6d 75 73 74 20 77 | 72 69 74 65 20 74 68 69 |u must w|rite thi|
|00003870| 73 20 65 78 70 6c 69 63 | 69 74 6c 79 20 69 6e 20 |s explic|itly in |
|00003880| 74 68 65 20 73 63 72 69 | 70 74 2c 20 65 2e 67 2e |the scri|pt, e.g.|
|00003890| 0a 5c 76 65 72 62 5c 69 | 6d 70 6f 72 74 20 6f 73 |.\verb\i|mport os|
|000038a0| 3b 5c 20 5c 76 65 72 62 | 5c 65 78 65 63 66 69 6c |;\ \verb|\execfil|
|000038b0| 65 28 6f 73 2e 65 6e 76 | 69 72 6f 6e 5b 27 50 59 |e(os.env|iron['PY|
|000038c0| 54 48 4f 4e 53 54 41 52 | 54 55 50 27 5d 29 5c 2e |THONSTAR|TUP'])\.|
|000038d0| 0a 0a 5c 73 65 63 74 69 | 6f 6e 7b 49 6e 74 65 72 |..\secti|on{Inter|
|000038e0| 61 63 74 69 76 65 20 49 | 6e 70 75 74 20 45 64 69 |active I|nput Edi|
|000038f0| 74 69 6e 67 20 61 6e 64 | 20 48 69 73 74 6f 72 79 |ting and| History|
|00003900| 20 53 75 62 73 74 69 74 | 75 74 69 6f 6e 7d 0a 0a | Substit|ution}..|
|00003910| 53 6f 6d 65 20 76 65 72 | 73 69 6f 6e 73 20 6f 66 |Some ver|sions of|
|00003920| 20 74 68 65 20 50 79 74 | 68 6f 6e 20 69 6e 74 65 | the Pyt|hon inte|
|00003930| 72 70 72 65 74 65 72 20 | 73 75 70 70 6f 72 74 20 |rpreter |support |
|00003940| 65 64 69 74 69 6e 67 20 | 6f 66 20 74 68 65 20 63 |editing |of the c|
|00003950| 75 72 72 65 6e 74 0a 69 | 6e 70 75 74 20 6c 69 6e |urrent.i|nput lin|
|00003960| 65 20 61 6e 64 20 68 69 | 73 74 6f 72 79 20 73 75 |e and hi|story su|
|00003970| 62 73 74 69 74 75 74 69 | 6f 6e 2c 20 73 69 6d 69 |bstituti|on, simi|
|00003980| 6c 61 72 20 74 6f 20 66 | 61 63 69 6c 69 74 69 65 |lar to f|acilitie|
|00003990| 73 20 66 6f 75 6e 64 20 | 69 6e 0a 74 68 65 20 4b |s found |in.the K|
|000039a0| 6f 72 6e 20 73 68 65 6c | 6c 20 61 6e 64 20 74 68 |orn shel|l and th|
|000039b0| 65 20 47 4e 55 20 42 61 | 73 68 20 73 68 65 6c 6c |e GNU Ba|sh shell|
|000039c0| 2e 20 20 54 68 69 73 20 | 69 73 20 69 6d 70 6c 65 |. This |is imple|
|000039d0| 6d 65 6e 74 65 64 20 75 | 73 69 6e 67 20 74 68 65 |mented u|sing the|
|000039e0| 0a 7b 5c 65 6d 20 47 4e | 55 5c 20 52 65 61 64 6c |.{\em GN|U\ Readl|
|000039f0| 69 6e 65 7d 20 6c 69 62 | 72 61 72 79 2c 20 77 68 |ine} lib|rary, wh|
|00003a00| 69 63 68 20 73 75 70 70 | 6f 72 74 73 20 45 6d 61 |ich supp|orts Ema|
|00003a10| 63 73 2d 73 74 79 6c 65 | 20 61 6e 64 20 76 69 2d |cs-style| and vi-|
|00003a20| 73 74 79 6c 65 0a 65 64 | 69 74 69 6e 67 2e 20 20 |style.ed|iting. |
|00003a30| 54 68 69 73 20 6c 69 62 | 72 61 72 79 20 68 61 73 |This lib|rary has|
|00003a40| 20 69 74 73 20 6f 77 6e | 20 64 6f 63 75 6d 65 6e | its own| documen|
|00003a50| 74 61 74 69 6f 6e 20 77 | 68 69 63 68 20 49 20 77 |tation w|hich I w|
|00003a60| 6f 6e 27 74 0a 64 75 70 | 6c 69 63 61 74 65 20 68 |on't.dup|licate h|
|00003a70| 65 72 65 3b 20 68 6f 77 | 65 76 65 72 2c 20 74 68 |ere; how|ever, th|
|00003a80| 65 20 62 61 73 69 63 73 | 20 61 72 65 20 65 61 73 |e basics| are eas|
|00003a90| 69 6c 79 20 65 78 70 6c | 61 69 6e 65 64 2e 0a 0a |ily expl|ained...|
|00003aa0| 50 65 72 68 61 70 73 20 | 74 68 65 20 71 75 69 63 |Perhaps |the quic|
|00003ab0| 6b 65 73 74 20 63 68 65 | 63 6b 20 74 6f 20 73 65 |kest che|ck to se|
|00003ac0| 65 20 77 68 65 74 68 65 | 72 20 63 6f 6d 6d 61 6e |e whethe|r comman|
|00003ad0| 64 20 6c 69 6e 65 20 65 | 64 69 74 69 6e 67 20 69 |d line e|diting i|
|00003ae0| 73 0a 73 75 70 70 6f 72 | 74 65 64 20 69 73 20 74 |s.suppor|ted is t|
|00003af0| 79 70 69 6e 67 20 43 6f | 6e 74 72 6f 6c 2d 50 20 |yping Co|ntrol-P |
|00003b00| 74 6f 20 74 68 65 20 66 | 69 72 73 74 20 50 79 74 |to the f|irst Pyt|
|00003b10| 68 6f 6e 20 70 72 6f 6d | 70 74 20 79 6f 75 20 67 |hon prom|pt you g|
|00003b20| 65 74 2e 20 20 49 66 0a | 69 74 20 62 65 65 70 73 |et. If.|it beeps|
|00003b30| 2c 20 79 6f 75 20 68 61 | 76 65 20 63 6f 6d 6d 61 |, you ha|ve comma|
|00003b40| 6e 64 20 6c 69 6e 65 20 | 65 64 69 74 69 6e 67 2e |nd line |editing.|
|00003b50| 20 20 49 66 20 6e 6f 74 | 68 69 6e 67 20 61 70 70 | If not|hing app|
|00003b60| 65 61 72 73 20 74 6f 0a | 68 61 70 70 65 6e 2c 20 |ears to.|happen, |
|00003b70| 6f 72 20 69 66 20 5c 76 | 65 72 62 2f 5e 50 2f 20 |or if \v|erb/^P/ |
|00003b80| 69 73 20 65 63 68 6f 65 | 64 2c 20 79 6f 75 20 63 |is echoe|d, you c|
|00003b90| 61 6e 20 73 6b 69 70 20 | 74 68 65 20 72 65 73 74 |an skip |the rest|
|00003ba0| 20 6f 66 20 74 68 69 73 | 0a 73 65 63 74 69 6f 6e | of this|.section|
|00003bb0| 2e 0a 0a 5c 73 75 62 73 | 65 63 74 69 6f 6e 7b 4c |...\subs|ection{L|
|00003bc0| 69 6e 65 20 45 64 69 74 | 69 6e 67 7d 0a 0a 49 66 |ine Edit|ing}..If|
|00003bd0| 20 73 75 70 70 6f 72 74 | 65 64 2c 20 69 6e 70 75 | support|ed, inpu|
|00003be0| 74 20 6c 69 6e 65 20 65 | 64 69 74 69 6e 67 20 69 |t line e|diting i|
|00003bf0| 73 20 61 63 74 69 76 65 | 20 77 68 65 6e 65 76 65 |s active| wheneve|
|00003c00| 72 20 74 68 65 20 69 6e | 74 65 72 70 72 65 74 65 |r the in|terprete|
|00003c10| 72 0a 70 72 69 6e 74 73 | 20 61 20 70 72 69 6d 61 |r.prints| a prima|
|00003c20| 72 79 20 6f 72 20 73 65 | 63 6f 6e 64 61 72 79 20 |ry or se|condary |
|00003c30| 70 72 6f 6d 70 74 2e 20 | 20 54 68 65 20 63 75 72 |prompt. | The cur|
|00003c40| 72 65 6e 74 20 6c 69 6e | 65 20 63 61 6e 20 62 65 |rent lin|e can be|
|00003c50| 20 65 64 69 74 65 64 0a | 75 73 69 6e 67 20 74 68 | edited.|using th|
|00003c60| 65 20 63 6f 6e 76 65 6e | 74 69 6f 6e 61 6c 20 45 |e conven|tional E|
|00003c70| 6d 61 63 73 20 63 6f 6e | 74 72 6f 6c 20 63 68 61 |macs con|trol cha|
|00003c80| 72 61 63 74 65 72 73 2e | 20 20 54 68 65 20 6d 6f |racters.| The mo|
|00003c90| 73 74 20 69 6d 70 6f 72 | 74 61 6e 74 0a 6f 66 20 |st impor|tant.of |
|00003ca0| 74 68 65 73 65 20 61 72 | 65 3a 20 43 2d 41 20 28 |these ar|e: C-A (|
|00003cb0| 43 6f 6e 74 72 6f 6c 2d | 41 29 20 6d 6f 76 65 73 |Control-|A) moves|
|00003cc0| 20 74 68 65 20 63 75 72 | 73 6f 72 20 74 6f 20 74 | the cur|sor to t|
|00003cd0| 68 65 20 62 65 67 69 6e | 6e 69 6e 67 20 6f 66 20 |he begin|ning of |
|00003ce0| 74 68 65 0a 6c 69 6e 65 | 2c 20 43 2d 45 20 74 6f |the.line|, C-E to|
|00003cf0| 20 74 68 65 20 65 6e 64 | 2c 20 43 2d 42 20 6d 6f | the end|, C-B mo|
|00003d00| 76 65 73 20 69 74 20 6f | 6e 65 20 70 6f 73 69 74 |ves it o|ne posit|
|00003d10| 69 6f 6e 20 74 6f 20 74 | 68 65 20 6c 65 66 74 2c |ion to t|he left,|
|00003d20| 20 43 2d 46 20 74 6f 0a | 74 68 65 20 72 69 67 68 | C-F to.|the righ|
|00003d30| 74 2e 20 20 42 61 63 6b | 73 70 61 63 65 20 65 72 |t. Back|space er|
|00003d40| 61 73 65 73 20 74 68 65 | 20 63 68 61 72 61 63 74 |ases the| charact|
|00003d50| 65 72 20 74 6f 20 74 68 | 65 20 6c 65 66 74 20 6f |er to th|e left o|
|00003d60| 66 20 74 68 65 20 63 75 | 72 73 6f 72 2c 0a 43 2d |f the cu|rsor,.C-|
|00003d70| 44 20 74 68 65 20 63 68 | 61 72 61 63 74 65 72 20 |D the ch|aracter |
|00003d80| 74 6f 20 69 74 73 20 72 | 69 67 68 74 2e 20 20 43 |to its r|ight. C|
|00003d90| 2d 4b 20 6b 69 6c 6c 73 | 20 28 65 72 61 73 65 73 |-K kills| (erases|
|00003da0| 29 20 74 68 65 20 72 65 | 73 74 20 6f 66 20 74 68 |) the re|st of th|
|00003db0| 65 0a 6c 69 6e 65 20 74 | 6f 20 74 68 65 20 72 69 |e.line t|o the ri|
|00003dc0| 67 68 74 20 6f 66 20 74 | 68 65 20 63 75 72 73 6f |ght of t|he curso|
|00003dd0| 72 2c 20 43 2d 59 20 79 | 61 6e 6b 73 20 62 61 63 |r, C-Y y|anks bac|
|00003de0| 6b 20 74 68 65 20 6c 61 | 73 74 20 6b 69 6c 6c 65 |k the la|st kille|
|00003df0| 64 0a 73 74 72 69 6e 67 | 2e 20 20 43 2d 75 6e 64 |d.string|. C-und|
|00003e00| 65 72 73 63 6f 72 65 20 | 75 6e 64 6f 65 73 20 74 |erscore |undoes t|
|00003e10| 68 65 20 6c 61 73 74 20 | 63 68 61 6e 67 65 20 79 |he last |change y|
|00003e20| 6f 75 20 6d 61 64 65 3b | 20 69 74 20 63 61 6e 20 |ou made;| it can |
|00003e30| 62 65 0a 72 65 70 65 61 | 74 65 64 20 66 6f 72 20 |be.repea|ted for |
|00003e40| 63 75 6d 75 6c 61 74 69 | 76 65 20 65 66 66 65 63 |cumulati|ve effec|
|00003e50| 74 2e 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |t...\sub|section{|
|00003e60| 48 69 73 74 6f 72 79 20 | 53 75 62 73 74 69 74 75 |History |Substitu|
|00003e70| 74 69 6f 6e 7d 0a 0a 48 | 69 73 74 6f 72 79 20 73 |tion}..H|istory s|
|00003e80| 75 62 73 74 69 74 75 74 | 69 6f 6e 20 77 6f 72 6b |ubstitut|ion work|
|00003e90| 73 20 61 73 20 66 6f 6c | 6c 6f 77 73 2e 20 20 41 |s as fol|lows. A|
|00003ea0| 6c 6c 20 6e 6f 6e 2d 65 | 6d 70 74 79 20 69 6e 70 |ll non-e|mpty inp|
|00003eb0| 75 74 20 6c 69 6e 65 73 | 0a 69 73 73 75 65 64 20 |ut lines|.issued |
|00003ec0| 61 72 65 20 73 61 76 65 | 64 20 69 6e 20 61 20 68 |are save|d in a h|
|00003ed0| 69 73 74 6f 72 79 20 62 | 75 66 66 65 72 2c 20 61 |istory b|uffer, a|
|00003ee0| 6e 64 20 77 68 65 6e 20 | 61 20 6e 65 77 20 70 72 |nd when |a new pr|
|00003ef0| 6f 6d 70 74 20 69 73 20 | 67 69 76 65 6e 0a 79 6f |ompt is |given.yo|
|00003f00| 75 20 61 72 65 20 70 6f | 73 69 74 69 6f 6e 65 64 |u are po|sitioned|
|00003f10| 20 6f 6e 20 61 20 6e 65 | 77 20 6c 69 6e 65 20 61 | on a ne|w line a|
|00003f20| 74 20 74 68 65 20 62 6f | 74 74 6f 6d 20 6f 66 20 |t the bo|ttom of |
|00003f30| 74 68 69 73 20 62 75 66 | 66 65 72 2e 20 20 43 2d |this buf|fer. C-|
|00003f40| 50 0a 6d 6f 76 65 73 20 | 6f 6e 65 20 6c 69 6e 65 |P.moves |one line|
|00003f50| 20 75 70 20 28 62 61 63 | 6b 29 20 69 6e 20 74 68 | up (bac|k) in th|
|00003f60| 65 20 68 69 73 74 6f 72 | 79 20 62 75 66 66 65 72 |e histor|y buffer|
|00003f70| 2c 20 43 2d 4e 20 6d 6f | 76 65 73 20 6f 6e 65 20 |, C-N mo|ves one |
|00003f80| 64 6f 77 6e 2e 0a 41 6e | 79 20 6c 69 6e 65 20 69 |down..An|y line i|
|00003f90| 6e 20 74 68 65 20 68 69 | 73 74 6f 72 79 20 62 75 |n the hi|story bu|
|00003fa0| 66 66 65 72 20 63 61 6e | 20 62 65 20 65 64 69 74 |ffer can| be edit|
|00003fb0| 65 64 3b 20 61 6e 20 61 | 73 74 65 72 69 73 6b 20 |ed; an a|sterisk |
|00003fc0| 61 70 70 65 61 72 73 20 | 69 6e 0a 66 72 6f 6e 74 |appears |in.front|
|00003fd0| 20 6f 66 20 74 68 65 20 | 70 72 6f 6d 70 74 20 74 | of the |prompt t|
|00003fe0| 6f 20 6d 61 72 6b 20 61 | 20 6c 69 6e 65 20 61 73 |o mark a| line as|
|00003ff0| 20 6d 6f 64 69 66 69 65 | 64 2e 20 20 50 72 65 73 | modifie|d. Pres|
|00004000| 73 69 6e 67 20 74 68 65 | 20 52 65 74 75 72 6e 0a |sing the| Return.|
|00004010| 6b 65 79 20 70 61 73 73 | 65 73 20 74 68 65 20 63 |key pass|es the c|
|00004020| 75 72 72 65 6e 74 20 6c | 69 6e 65 20 74 6f 20 74 |urrent l|ine to t|
|00004030| 68 65 20 69 6e 74 65 72 | 70 72 65 74 65 72 2e 20 |he inter|preter. |
|00004040| 20 43 2d 52 20 73 74 61 | 72 74 73 20 61 6e 0a 69 | C-R sta|rts an.i|
|00004050| 6e 63 72 65 6d 65 6e 74 | 61 6c 20 72 65 76 65 72 |ncrement|al rever|
|00004060| 73 65 20 73 65 61 72 63 | 68 3b 20 43 2d 53 20 73 |se searc|h; C-S s|
|00004070| 74 61 72 74 73 20 61 20 | 66 6f 72 77 61 72 64 20 |tarts a |forward |
|00004080| 73 65 61 72 63 68 2e 0a | 0a 5c 73 75 62 73 65 63 |search..|.\subsec|
|00004090| 74 69 6f 6e 7b 4b 65 79 | 20 42 69 6e 64 69 6e 67 |tion{Key| Binding|
|000040a0| 73 7d 0a 0a 54 68 65 20 | 6b 65 79 20 62 69 6e 64 |s}..The |key bind|
|000040b0| 69 6e 67 73 20 61 6e 64 | 20 73 6f 6d 65 20 6f 74 |ings and| some ot|
|000040c0| 68 65 72 20 70 61 72 61 | 6d 65 74 65 72 73 20 6f |her para|meters o|
|000040d0| 66 20 74 68 65 20 52 65 | 61 64 6c 69 6e 65 20 6c |f the Re|adline l|
|000040e0| 69 62 72 61 72 79 20 63 | 61 6e 0a 62 65 20 63 75 |ibrary c|an.be cu|
|000040f0| 73 74 6f 6d 69 7a 65 64 | 20 62 79 20 70 6c 61 63 |stomized| by plac|
|00004100| 69 6e 67 20 63 6f 6d 6d | 61 6e 64 73 20 69 6e 20 |ing comm|ands in |
|00004110| 61 6e 20 69 6e 69 74 69 | 61 6c 69 7a 61 74 69 6f |an initi|alizatio|
|00004120| 6e 20 66 69 6c 65 20 63 | 61 6c 6c 65 64 0a 7b 5c |n file c|alled.{\|
|00004130| 74 74 20 5c 24 48 4f 4d | 45 2f 2e 69 6e 70 75 74 |tt \$HOM|E/.input|
|00004140| 72 63 7d 2e 20 20 4b 65 | 79 20 62 69 6e 64 69 6e |rc}. Ke|y bindin|
|00004150| 67 73 20 68 61 76 65 20 | 74 68 65 20 66 6f 72 6d |gs have |the form|
|00004160| 0a 0a 5c 62 63 6f 64 65 | 5c 62 65 67 69 6e 7b 76 |..\bcode|\begin{v|
|00004170| 65 72 62 61 74 69 6d 7d | 0a 6b 65 79 2d 6e 61 6d |erbatim}|.key-nam|
|00004180| 65 3a 20 66 75 6e 63 74 | 69 6f 6e 2d 6e 61 6d 65 |e: funct|ion-name|
|00004190| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 5c |.\end{ve|rbatim}\|
|000041a0| 65 63 6f 64 65 0a 25 0a | 6f 72 0a 0a 5c 62 63 6f |ecode.%.|or..\bco|
|000041b0| 64 65 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |de\begin|{verbati|
|000041c0| 6d 7d 0a 22 73 74 72 69 | 6e 67 22 3a 20 66 75 6e |m}."stri|ng": fun|
|000041d0| 63 74 69 6f 6e 2d 6e 61 | 6d 65 0a 5c 65 6e 64 7b |ction-na|me.\end{|
|000041e0| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0a |verbatim|}\ecode.|
|000041f0| 25 0a 61 6e 64 20 6f 70 | 74 69 6f 6e 73 20 63 61 |%.and op|tions ca|
|00004200| 6e 20 62 65 20 73 65 74 | 20 77 69 74 68 0a 0a 5c |n be set| with..\|
|00004210| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|00004220| 61 74 69 6d 7d 0a 73 65 | 74 20 6f 70 74 69 6f 6e |atim}.se|t option|
|00004230| 2d 6e 61 6d 65 20 76 61 | 6c 75 65 0a 5c 65 6e 64 |-name va|lue.\end|
|00004240| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|00004250| 0a 25 0a 46 6f 72 20 65 | 78 61 6d 70 6c 65 3a 0a |.%.For e|xample:.|
|00004260| 0a 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|00004270| 72 62 61 74 69 6d 7d 0a | 23 20 49 20 70 72 65 66 |rbatim}.|# I pref|
|00004280| 65 72 20 76 69 2d 73 74 | 79 6c 65 20 65 64 69 74 |er vi-st|yle edit|
|00004290| 69 6e 67 3a 0a 73 65 74 | 20 65 64 69 74 69 6e 67 |ing:.set| editing|
|000042a0| 2d 6d 6f 64 65 20 76 69 | 0a 23 20 45 64 69 74 20 |-mode vi|.# Edit |
|000042b0| 75 73 69 6e 67 20 61 20 | 73 69 6e 67 6c 65 20 6c |using a |single l|
|000042c0| 69 6e 65 3a 0a 73 65 74 | 20 68 6f 72 69 7a 6f 6e |ine:.set| horizon|
|000042d0| 74 61 6c 2d 73 63 72 6f | 6c 6c 2d 6d 6f 64 65 20 |tal-scro|ll-mode |
|000042e0| 4f 6e 0a 23 20 52 65 62 | 69 6e 64 20 73 6f 6d 65 |On.# Reb|ind some|
|000042f0| 20 6b 65 79 73 3a 0a 4d | 65 74 61 2d 68 3a 20 62 | keys:.M|eta-h: b|
|00004300| 61 63 6b 77 61 72 64 2d | 6b 69 6c 6c 2d 77 6f 72 |ackward-|kill-wor|
|00004310| 64 0a 22 5c 43 2d 75 22 | 3a 20 75 6e 69 76 65 72 |d."\C-u"|: univer|
|00004320| 73 61 6c 2d 61 72 67 75 | 6d 65 6e 74 0a 22 5c 43 |sal-argu|ment."\C|
|00004330| 2d 78 5c 43 2d 72 22 3a | 20 72 65 2d 72 65 61 64 |-x\C-r":| re-read|
|00004340| 2d 69 6e 69 74 2d 66 69 | 6c 65 0a 5c 65 6e 64 7b |-init-fi|le.\end{|
|00004350| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0a |verbatim|}\ecode.|
|00004360| 25 0a 4e 6f 74 65 20 74 | 68 61 74 20 74 68 65 20 |%.Note t|hat the |
|00004370| 64 65 66 61 75 6c 74 20 | 62 69 6e 64 69 6e 67 20 |default |binding |
|00004380| 66 6f 72 20 54 41 42 20 | 69 6e 20 50 79 74 68 6f |for TAB |in Pytho|
|00004390| 6e 20 69 73 20 74 6f 20 | 69 6e 73 65 72 74 20 61 |n is to |insert a|
|000043a0| 20 54 41 42 0a 69 6e 73 | 74 65 61 64 20 6f 66 20 | TAB.ins|tead of |
|000043b0| 52 65 61 64 6c 69 6e 65 | 27 73 20 64 65 66 61 75 |Readline|'s defau|
|000043c0| 6c 74 20 66 69 6c 65 6e | 61 6d 65 20 63 6f 6d 70 |lt filen|ame comp|
|000043d0| 6c 65 74 69 6f 6e 20 66 | 75 6e 63 74 69 6f 6e 2e |letion f|unction.|
|000043e0| 20 20 49 66 20 79 6f 75 | 0a 69 6e 73 69 73 74 2c | If you|.insist,|
|000043f0| 20 79 6f 75 20 63 61 6e | 20 6f 76 65 72 72 69 64 | you can| overrid|
|00004400| 65 20 74 68 69 73 20 62 | 79 20 70 75 74 74 69 6e |e this b|y puttin|
|00004410| 67 0a 0a 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |g..\bcod|e\begin{|
|00004420| 76 65 72 62 61 74 69 6d | 7d 0a 54 41 42 3a 20 63 |verbatim|}.TAB: c|
|00004430| 6f 6d 70 6c 65 74 65 0a | 5c 65 6e 64 7b 76 65 72 |omplete.|\end{ver|
|00004440| 62 61 74 69 6d 7d 5c 65 | 63 6f 64 65 0a 25 0a 69 |batim}\e|code.%.i|
|00004450| 6e 20 79 6f 75 72 20 7b | 5c 74 74 20 5c 24 48 4f |n your {|\tt \$HO|
|00004460| 4d 45 2f 2e 69 6e 70 75 | 74 72 63 7d 2e 20 20 28 |ME/.inpu|trc}. (|
|00004470| 4f 66 20 63 6f 75 72 73 | 65 2c 20 74 68 69 73 20 |Of cours|e, this |
|00004480| 6d 61 6b 65 73 20 69 74 | 20 68 61 72 64 20 74 6f |makes it| hard to|
|00004490| 20 74 79 70 65 0a 69 6e | 64 65 6e 74 65 64 20 63 | type.in|dented c|
|000044a0| 6f 6e 74 69 6e 75 61 74 | 69 6f 6e 20 6c 69 6e 65 |ontinuat|ion line|
|000044b0| 73 2e 2e 2e 29 0a 0a 5c | 73 75 62 73 65 63 74 69 |s...)..\|subsecti|
|000044c0| 6f 6e 7b 43 6f 6d 6d 65 | 6e 74 61 72 79 7d 0a 0a |on{Comme|ntary}..|
|000044d0| 54 68 69 73 20 66 61 63 | 69 6c 69 74 79 20 69 73 |This fac|ility is|
|000044e0| 20 61 6e 20 65 6e 6f 72 | 6d 6f 75 73 20 73 74 65 | an enor|mous ste|
|000044f0| 70 20 66 6f 72 77 61 72 | 64 20 63 6f 6d 70 61 72 |p forwar|d compar|
|00004500| 65 64 20 74 6f 20 70 72 | 65 76 69 6f 75 73 0a 76 |ed to pr|evious.v|
|00004510| 65 72 73 69 6f 6e 73 20 | 6f 66 20 74 68 65 20 69 |ersions |of the i|
|00004520| 6e 74 65 72 70 72 65 74 | 65 72 3b 20 68 6f 77 65 |nterpret|er; howe|
|00004530| 76 65 72 2c 20 73 6f 6d | 65 20 77 69 73 68 65 73 |ver, som|e wishes|
|00004540| 20 61 72 65 20 6c 65 66 | 74 3a 20 49 74 20 77 6f | are lef|t: It wo|
|00004550| 75 6c 64 0a 62 65 20 6e | 69 63 65 20 69 66 20 74 |uld.be n|ice if t|
|00004560| 68 65 20 70 72 6f 70 65 | 72 20 69 6e 64 65 6e 74 |he prope|r indent|
|00004570| 61 74 69 6f 6e 20 77 65 | 72 65 20 73 75 67 67 65 |ation we|re sugge|
|00004580| 73 74 65 64 20 6f 6e 20 | 63 6f 6e 74 69 6e 75 61 |sted on |continua|
|00004590| 74 69 6f 6e 20 6c 69 6e | 65 73 0a 28 74 68 65 20 |tion lin|es.(the |
|000045a0| 70 61 72 73 65 72 20 6b | 6e 6f 77 73 20 69 66 20 |parser k|nows if |
|000045b0| 61 6e 20 69 6e 64 65 6e | 74 20 74 6f 6b 65 6e 20 |an inden|t token |
|000045c0| 69 73 20 72 65 71 75 69 | 72 65 64 20 6e 65 78 74 |is requi|red next|
|000045d0| 29 2e 20 20 54 68 65 0a | 63 6f 6d 70 6c 65 74 69 |). The.|completi|
|000045e0| 6f 6e 20 6d 65 63 68 61 | 6e 69 73 6d 20 6d 69 67 |on mecha|nism mig|
|000045f0| 68 74 20 75 73 65 20 74 | 68 65 20 69 6e 74 65 72 |ht use t|he inter|
|00004600| 70 72 65 74 65 72 27 73 | 20 73 79 6d 62 6f 6c 20 |preter's| symbol |
|00004610| 74 61 62 6c 65 2e 20 20 | 41 0a 63 6f 6d 6d 61 6e |table. |A.comman|
|00004620| 64 20 74 6f 20 63 68 65 | 63 6b 20 28 6f 72 20 65 |d to che|ck (or e|
|00004630| 76 65 6e 20 73 75 67 67 | 65 73 74 29 20 6d 61 74 |ven sugg|est) mat|
|00004640| 63 68 69 6e 67 20 70 61 | 72 65 6e 74 68 65 73 65 |ching pa|renthese|
|00004650| 73 2c 20 71 75 6f 74 65 | 73 20 65 74 63 2e 0a 77 |s, quote|s etc..w|
|00004660| 6f 75 6c 64 20 61 6c 73 | 6f 20 62 65 20 75 73 65 |ould als|o be use|
|00004670| 66 75 6c 2e 0a 0a 0a 5c | 63 68 61 70 74 65 72 7b |ful....\|chapter{|
|00004680| 41 6e 20 49 6e 66 6f 72 | 6d 61 6c 20 49 6e 74 72 |An Infor|mal Intr|
|00004690| 6f 64 75 63 74 69 6f 6e | 20 74 6f 20 50 79 74 68 |oduction| to Pyth|
|000046a0| 6f 6e 7d 0a 0a 49 6e 20 | 74 68 65 20 66 6f 6c 6c |on}..In |the foll|
|000046b0| 6f 77 69 6e 67 20 65 78 | 61 6d 70 6c 65 73 2c 20 |owing ex|amples, |
|000046c0| 69 6e 70 75 74 20 61 6e | 64 20 6f 75 74 70 75 74 |input an|d output|
|000046d0| 20 61 72 65 20 64 69 73 | 74 69 6e 67 75 69 73 68 | are dis|tinguish|
|000046e0| 65 64 20 62 79 20 74 68 | 65 0a 70 72 65 73 65 6e |ed by th|e.presen|
|000046f0| 63 65 20 6f 72 20 61 62 | 73 65 6e 63 65 20 6f 66 |ce or ab|sence of|
|00004700| 20 70 72 6f 6d 70 74 73 | 20 28 7b 5c 74 74 20 3e | prompts| ({\tt >|
|00004710| 3e 3e 7d 20 61 6e 64 20 | 7b 5c 74 74 20 2e 2e 2e |>>} and |{\tt ...|
|00004720| 7d 29 3a 20 74 6f 20 72 | 65 70 65 61 74 0a 74 68 |}): to r|epeat.th|
|00004730| 65 20 65 78 61 6d 70 6c | 65 2c 20 79 6f 75 20 6d |e exampl|e, you m|
|00004740| 75 73 74 20 74 79 70 65 | 20 65 76 65 72 79 74 68 |ust type| everyth|
|00004750| 69 6e 67 20 61 66 74 65 | 72 20 74 68 65 20 70 72 |ing afte|r the pr|
|00004760| 6f 6d 70 74 2c 20 77 68 | 65 6e 20 74 68 65 0a 70 |ompt, wh|en the.p|
|00004770| 72 6f 6d 70 74 20 61 70 | 70 65 61 72 73 3b 20 6c |rompt ap|pears; l|
|00004780| 69 6e 65 73 20 74 68 61 | 74 20 64 6f 20 6e 6f 74 |ines tha|t do not|
|00004790| 20 62 65 67 69 6e 20 77 | 69 74 68 20 61 20 70 72 | begin w|ith a pr|
|000047a0| 6f 6d 70 74 20 61 72 65 | 20 6f 75 74 70 75 74 20 |ompt are| output |
|000047b0| 66 72 6f 6d 0a 74 68 65 | 20 69 6e 74 65 72 70 72 |from.the| interpr|
|000047c0| 65 74 65 72 2e 25 0a 5c | 66 6f 6f 74 6e 6f 74 65 |eter.%.\|footnote|
|000047d0| 7b 0a 20 20 20 20 20 20 | 20 20 49 27 64 20 70 72 |{. | I'd pr|
|000047e0| 65 66 65 72 20 74 6f 20 | 75 73 65 20 64 69 66 66 |efer to |use diff|
|000047f0| 65 72 65 6e 74 20 66 6f | 6e 74 73 20 74 6f 20 64 |erent fo|nts to d|
|00004800| 69 73 74 69 6e 67 75 69 | 73 68 20 69 6e 70 75 74 |istingui|sh input|
|00004810| 0a 20 20 20 20 20 20 20 | 20 66 72 6f 6d 20 6f 75 |. | from ou|
|00004820| 74 70 75 74 2c 20 62 75 | 74 20 74 68 65 20 61 6d |tput, bu|t the am|
|00004830| 6f 75 6e 74 20 6f 66 20 | 4c 61 54 65 58 20 68 61 |ount of |LaTeX ha|
|00004840| 63 6b 69 6e 67 20 74 68 | 61 74 20 77 6f 75 6c 64 |cking th|at would|
|00004850| 20 72 65 71 75 69 72 65 | 0a 20 20 20 20 20 20 20 | require|. |
|00004860| 20 69 73 20 63 75 72 72 | 65 6e 74 6c 79 20 62 65 | is curr|ently be|
|00004870| 79 6f 6e 64 20 6d 79 20 | 61 62 69 6c 69 74 79 2e |yond my |ability.|
|00004880| 0a 7d 0a 4e 6f 74 65 20 | 74 68 61 74 20 61 20 73 |.}.Note |that a s|
|00004890| 65 63 6f 6e 64 61 72 79 | 20 70 72 6f 6d 70 74 20 |econdary| prompt |
|000048a0| 6f 6e 20 61 20 6c 69 6e | 65 20 62 79 20 69 74 73 |on a lin|e by its|
|000048b0| 65 6c 66 20 69 6e 20 61 | 6e 20 65 78 61 6d 70 6c |elf in a|n exampl|
|000048c0| 65 20 6d 65 61 6e 73 0a | 79 6f 75 20 6d 75 73 74 |e means.|you must|
|000048d0| 20 74 79 70 65 20 61 20 | 62 6c 61 6e 6b 20 6c 69 | type a |blank li|
|000048e0| 6e 65 3b 20 74 68 69 73 | 20 69 73 20 75 73 65 64 |ne; this| is used|
|000048f0| 20 74 6f 20 65 6e 64 20 | 61 20 6d 75 6c 74 69 2d | to end |a multi-|
|00004900| 6c 69 6e 65 20 63 6f 6d | 6d 61 6e 64 2e 0a 0a 5c |line com|mand...\|
|00004910| 73 65 63 74 69 6f 6e 7b | 55 73 69 6e 67 20 50 79 |section{|Using Py|
|00004920| 74 68 6f 6e 20 61 73 20 | 61 20 43 61 6c 63 75 6c |thon as |a Calcul|
|00004930| 61 74 6f 72 7d 0a 0a 4c | 65 74 27 73 20 74 72 79 |ator}..L|et's try|
|00004940| 20 73 6f 6d 65 20 73 69 | 6d 70 6c 65 20 50 79 74 | some si|mple Pyt|
|00004950| 68 6f 6e 20 63 6f 6d 6d | 61 6e 64 73 2e 20 20 53 |hon comm|ands. S|
|00004960| 74 61 72 74 20 74 68 65 | 20 69 6e 74 65 72 70 72 |tart the| interpr|
|00004970| 65 74 65 72 20 61 6e 64 | 20 77 61 69 74 0a 66 6f |eter and| wait.fo|
|00004980| 72 20 74 68 65 20 70 72 | 69 6d 61 72 79 20 70 72 |r the pr|imary pr|
|00004990| 6f 6d 70 74 2c 20 7b 5c | 74 74 20 3e 3e 3e 7d 2e |ompt, {\|tt >>>}.|
|000049a0| 20 20 28 49 74 20 73 68 | 6f 75 6c 64 6e 27 74 20 | (It sh|ouldn't |
|000049b0| 74 61 6b 65 20 6c 6f 6e | 67 2e 29 0a 0a 5c 73 75 |take lon|g.)..\su|
|000049c0| 62 73 65 63 74 69 6f 6e | 7b 4e 75 6d 62 65 72 73 |bsection|{Numbers|
|000049d0| 7d 0a 0a 54 68 65 20 69 | 6e 74 65 72 70 72 65 74 |}..The i|nterpret|
|000049e0| 65 72 20 61 63 74 73 20 | 61 73 20 61 20 73 69 6d |er acts |as a sim|
|000049f0| 70 6c 65 20 63 61 6c 63 | 75 6c 61 74 6f 72 3a 20 |ple calc|ulator: |
|00004a00| 79 6f 75 20 63 61 6e 20 | 74 79 70 65 20 61 6e 0a |you can |type an.|
|00004a10| 65 78 70 72 65 73 73 69 | 6f 6e 20 61 74 20 69 74 |expressi|on at it|
|00004a20| 20 61 6e 64 20 69 74 20 | 77 69 6c 6c 20 77 72 69 | and it |will wri|
|00004a30| 74 65 20 74 68 65 20 76 | 61 6c 75 65 2e 20 20 45 |te the v|alue. E|
|00004a40| 78 70 72 65 73 73 69 6f | 6e 20 73 79 6e 74 61 78 |xpressio|n syntax|
|00004a50| 20 69 73 0a 73 74 72 61 | 69 67 68 74 66 6f 72 77 | is.stra|ightforw|
|00004a60| 61 72 64 3a 20 74 68 65 | 20 6f 70 65 72 61 74 6f |ard: the| operato|
|00004a70| 72 73 20 7b 5c 74 74 20 | 2b 7d 2c 20 7b 5c 74 74 |rs {\tt |+}, {\tt|
|00004a80| 20 2d 7d 2c 20 7b 5c 74 | 74 20 2a 7d 20 61 6e 64 | -}, {\t|t *} and|
|00004a90| 20 7b 5c 74 74 20 2f 7d | 0a 77 6f 72 6b 20 6a 75 | {\tt /}|.work ju|
|00004aa0| 73 74 20 6c 69 6b 65 20 | 69 6e 20 6d 6f 73 74 20 |st like |in most |
|00004ab0| 6f 74 68 65 72 20 6c 61 | 6e 67 75 61 67 65 73 20 |other la|nguages |
|00004ac0| 28 65 2e 67 2e 2c 20 50 | 61 73 63 61 6c 20 6f 72 |(e.g., P|ascal or|
|00004ad0| 20 43 29 3b 20 70 61 72 | 65 6e 74 68 65 73 65 73 | C); par|entheses|
|00004ae0| 0a 63 61 6e 20 62 65 20 | 75 73 65 64 20 66 6f 72 |.can be |used for|
|00004af0| 20 67 72 6f 75 70 69 6e | 67 2e 20 20 46 6f 72 20 | groupin|g. For |
|00004b00| 65 78 61 6d 70 6c 65 3a | 0a 0a 5c 62 63 6f 64 65 |example:|..\bcode|
|00004b10| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00004b20| 0a 3e 3e 3e 20 32 2b 32 | 0a 34 0a 3e 3e 3e 20 23 |.>>> 2+2|.4.>>> #|
|00004b30| 20 54 68 69 73 20 69 73 | 20 61 20 63 6f 6d 6d 65 | This is| a comme|
|00004b40| 6e 74 0a 2e 2e 2e 20 32 | 2b 32 0a 34 0a 3e 3e 3e |nt.... 2|+2.4.>>>|
|00004b50| 20 32 2b 32 20 20 23 20 | 61 6e 64 20 61 20 63 6f | 2+2 # |and a co|
|00004b60| 6d 6d 65 6e 74 20 6f 6e | 20 74 68 65 20 73 61 6d |mment on| the sam|
|00004b70| 65 20 6c 69 6e 65 20 61 | 73 20 63 6f 64 65 0a 34 |e line a|s code.4|
|00004b80| 0a 3e 3e 3e 20 28 35 30 | 2d 35 2a 36 29 2f 34 0a |.>>> (50|-5*6)/4.|
|00004b90| 35 0a 3e 3e 3e 20 23 20 | 49 6e 74 65 67 65 72 20 |5.>>> # |Integer |
|00004ba0| 64 69 76 69 73 69 6f 6e | 20 72 65 74 75 72 6e 73 |division| returns|
|00004bb0| 20 74 68 65 20 66 6c 6f | 6f 72 3a 0a 2e 2e 2e 20 | the flo|or:.... |
|00004bc0| 37 2f 33 0a 32 0a 3e 3e | 3e 20 37 2f 2d 33 0a 2d |7/3.2.>>|> 7/-3.-|
|00004bd0| 33 0a 3e 3e 3e 20 0a 5c | 65 6e 64 7b 76 65 72 62 |3.>>> .\|end{verb|
|00004be0| 61 74 69 6d 7d 5c 65 63 | 6f 64 65 0a 25 0a 4c 69 |atim}\ec|ode.%.Li|
|00004bf0| 6b 65 20 69 6e 20 43 2c | 20 74 68 65 20 65 71 75 |ke in C,| the equ|
|00004c00| 61 6c 20 73 69 67 6e 20 | 28 7b 5c 74 74 20 3d 7d |al sign |({\tt =}|
|00004c10| 29 20 69 73 20 75 73 65 | 64 20 74 6f 20 61 73 73 |) is use|d to ass|
|00004c20| 69 67 6e 20 61 20 76 61 | 6c 75 65 20 74 6f 20 61 |ign a va|lue to a|
|00004c30| 0a 76 61 72 69 61 62 6c | 65 2e 20 20 54 68 65 20 |.variabl|e. The |
|00004c40| 76 61 6c 75 65 20 6f 66 | 20 61 6e 20 61 73 73 69 |value of| an assi|
|00004c50| 67 6e 6d 65 6e 74 20 69 | 73 20 6e 6f 74 20 77 72 |gnment i|s not wr|
|00004c60| 69 74 74 65 6e 3a 0a 0a | 5c 62 63 6f 64 65 5c 62 |itten:..|\bcode\b|
|00004c70| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 3e |egin{ver|batim}.>|
|00004c80| 3e 3e 20 77 69 64 74 68 | 20 3d 20 32 30 0a 3e 3e |>> width| = 20.>>|
|00004c90| 3e 20 68 65 69 67 68 74 | 20 3d 20 35 2a 39 0a 3e |> height| = 5*9.>|
|00004ca0| 3e 3e 20 77 69 64 74 68 | 20 2a 20 68 65 69 67 68 |>> width| * heigh|
|00004cb0| 74 0a 39 30 30 0a 3e 3e | 3e 20 0a 5c 65 6e 64 7b |t.900.>>|> .\end{|
|00004cc0| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0a |verbatim|}\ecode.|
|00004cd0| 25 0a 41 20 76 61 6c 75 | 65 20 63 61 6e 20 62 65 |%.A valu|e can be|
|00004ce0| 20 61 73 73 69 67 6e 65 | 64 20 74 6f 20 73 65 76 | assigne|d to sev|
|00004cf0| 65 72 61 6c 20 76 61 72 | 69 61 62 6c 65 73 20 73 |eral var|iables s|
|00004d00| 69 6d 75 6c 74 61 6e 65 | 6f 75 73 6c 79 3a 0a 0a |imultane|ously:..|
|00004d10| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00004d20| 62 61 74 69 6d 7d 0a 3e | 3e 3e 20 78 20 3d 20 79 |batim}.>|>> x = y|
|00004d30| 20 3d 20 7a 20 3d 20 30 | 20 20 23 20 5a 65 72 6f | = z = 0| # Zero|
|00004d40| 20 78 2c 20 79 20 61 6e | 64 20 7a 0a 3e 3e 3e 20 | x, y an|d z.>>> |
|00004d50| 78 0a 30 0a 3e 3e 3e 20 | 79 0a 30 0a 3e 3e 3e 20 |x.0.>>> |y.0.>>> |
|00004d60| 7a 0a 30 0a 3e 3e 3e 20 | 0a 5c 65 6e 64 7b 76 65 |z.0.>>> |.\end{ve|
|00004d70| 72 62 61 74 69 6d 7d 5c | 65 63 6f 64 65 0a 25 0a |rbatim}\|ecode.%.|
|00004d80| 54 68 65 72 65 20 69 73 | 20 66 75 6c 6c 20 73 75 |There is| full su|
|00004d90| 70 70 6f 72 74 20 66 6f | 72 20 66 6c 6f 61 74 69 |pport fo|r floati|
|00004da0| 6e 67 20 70 6f 69 6e 74 | 3b 20 6f 70 65 72 61 74 |ng point|; operat|
|00004db0| 6f 72 73 20 77 69 74 68 | 20 6d 69 78 65 64 20 74 |ors with| mixed t|
|00004dc0| 79 70 65 0a 6f 70 65 72 | 61 6e 64 73 20 63 6f 6e |ype.oper|ands con|
|00004dd0| 76 65 72 74 20 74 68 65 | 20 69 6e 74 65 67 65 72 |vert the| integer|
|00004de0| 20 6f 70 65 72 61 6e 64 | 20 74 6f 20 66 6c 6f 61 | operand| to floa|
|00004df0| 74 69 6e 67 20 70 6f 69 | 6e 74 3a 0a 0a 5c 62 63 |ting poi|nt:..\bc|
|00004e00| 6f 64 65 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |ode\begi|n{verbat|
|00004e10| 69 6d 7d 0a 3e 3e 3e 20 | 34 20 2a 20 32 2e 35 20 |im}.>>> |4 * 2.5 |
|00004e20| 2f 20 33 2e 33 0a 33 2e | 30 33 30 33 30 33 30 33 |/ 3.3.3.|03030303|
|00004e30| 30 33 0a 3e 3e 3e 20 37 | 2e 30 20 2f 20 32 0a 33 |03.>>> 7|.0 / 2.3|
|00004e40| 2e 35 0a 3e 3e 3e 20 0a | 5c 65 6e 64 7b 76 65 72 |.5.>>> .|\end{ver|
|00004e50| 62 61 74 69 6d 7d 5c 65 | 63 6f 64 65 0a 0a 5c 73 |batim}\e|code..\s|
|00004e60| 75 62 73 65 63 74 69 6f | 6e 7b 53 74 72 69 6e 67 |ubsectio|n{String|
|00004e70| 73 7d 0a 0a 42 65 73 69 | 64 65 73 20 6e 75 6d 62 |s}..Besi|des numb|
|00004e80| 65 72 73 2c 20 50 79 74 | 68 6f 6e 20 63 61 6e 20 |ers, Pyt|hon can |
|00004e90| 61 6c 73 6f 20 6d 61 6e | 69 70 75 6c 61 74 65 20 |also man|ipulate |
|00004ea0| 73 74 72 69 6e 67 73 2c | 20 65 6e 63 6c 6f 73 65 |strings,| enclose|
|00004eb0| 64 20 69 6e 0a 73 69 6e | 67 6c 65 20 71 75 6f 74 |d in.sin|gle quot|
|00004ec0| 65 73 20 6f 72 20 64 6f | 75 62 6c 65 20 71 75 6f |es or do|uble quo|
|00004ed0| 74 65 73 3a 0a 0a 5c 62 | 63 6f 64 65 5c 62 65 67 |tes:..\b|code\beg|
|00004ee0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 3e 3e 3e |in{verba|tim}.>>>|
|00004ef0| 20 27 73 70 61 6d 20 65 | 67 67 73 27 0a 27 73 70 | 'spam e|ggs'.'sp|
|00004f00| 61 6d 20 65 67 67 73 27 | 0a 3e 3e 3e 20 27 64 6f |am eggs'|.>>> 'do|
|00004f10| 65 73 6e 5c 27 74 27 0a | 22 64 6f 65 73 6e 27 74 |esn\'t'.|"doesn't|
|00004f20| 22 0a 3e 3e 3e 20 22 64 | 6f 65 73 6e 27 74 22 0a |".>>> "d|oesn't".|
|00004f30| 22 64 6f 65 73 6e 27 74 | 22 0a 3e 3e 3e 20 27 22 |"doesn't|".>>> '"|
|00004f40| 59 65 73 2c 22 20 68 65 | 20 73 61 69 64 2e 27 0a |Yes," he| said.'.|
|00004f50| 27 22 59 65 73 2c 22 20 | 68 65 20 73 61 69 64 2e |'"Yes," |he said.|
|00004f60| 27 0a 3e 3e 3e 20 22 5c | 22 59 65 73 2c 5c 22 20 |'.>>> "\|"Yes,\" |
|00004f70| 68 65 20 73 61 69 64 2e | 22 0a 27 22 59 65 73 2c |he said.|".'"Yes,|
|00004f80| 22 20 68 65 20 73 61 69 | 64 2e 27 0a 3e 3e 3e 20 |" he sai|d.'.>>> |
|00004f90| 27 22 49 73 6e 5c 27 74 | 2c 22 20 73 68 65 20 73 |'"Isn\'t|," she s|
|00004fa0| 61 69 64 2e 27 0a 27 22 | 49 73 6e 5c 27 74 2c 22 |aid.'.'"|Isn\'t,"|
|00004fb0| 20 73 68 65 20 73 61 69 | 64 2e 27 0a 3e 3e 3e 20 | she sai|d.'.>>> |
|00004fc0| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 5c |.\end{ve|rbatim}\|
|00004fd0| 65 63 6f 64 65 0a 25 0a | 53 74 72 69 6e 67 73 20 |ecode.%.|Strings |
|00004fe0| 61 72 65 20 77 72 69 74 | 74 65 6e 20 74 68 65 20 |are writ|ten the |
|00004ff0| 73 61 6d 65 20 77 61 79 | 20 61 73 20 74 68 65 79 |same way| as they|
|00005000| 20 61 72 65 20 74 79 70 | 65 64 20 66 6f 72 20 69 | are typ|ed for i|
|00005010| 6e 70 75 74 3a 20 69 6e | 73 69 64 65 0a 71 75 6f |nput: in|side.quo|
|00005020| 74 65 73 20 61 6e 64 20 | 77 69 74 68 20 71 75 6f |tes and |with quo|
|00005030| 74 65 73 20 61 6e 64 20 | 6f 74 68 65 72 20 66 75 |tes and |other fu|
|00005040| 6e 6e 79 20 63 68 61 72 | 61 63 74 65 72 73 20 65 |nny char|acters e|
|00005050| 73 63 61 70 65 64 20 62 | 79 20 62 61 63 6b 73 6c |scaped b|y backsl|
|00005060| 61 73 68 65 73 2c 0a 74 | 6f 20 73 68 6f 77 20 74 |ashes,.t|o show t|
|00005070| 68 65 20 70 72 65 63 69 | 73 65 20 76 61 6c 75 65 |he preci|se value|
|00005080| 2e 20 20 54 68 65 20 73 | 74 72 69 6e 67 20 69 73 |. The s|tring is|
|00005090| 20 65 6e 63 6c 6f 73 65 | 64 20 69 6e 20 64 6f 75 | enclose|d in dou|
|000050a0| 62 6c 65 20 71 75 6f 74 | 65 73 20 69 66 0a 74 68 |ble quot|es if.th|
|000050b0| 65 20 73 74 72 69 6e 67 | 20 63 6f 6e 74 61 69 6e |e string| contain|
|000050c0| 73 20 61 20 73 69 6e 67 | 6c 65 20 71 75 6f 74 65 |s a sing|le quote|
|000050d0| 20 61 6e 64 20 6e 6f 20 | 64 6f 75 62 6c 65 20 71 | and no |double q|
|000050e0| 75 6f 74 65 73 2c 20 65 | 6c 73 65 20 69 74 27 73 |uotes, e|lse it's|
|000050f0| 0a 65 6e 63 6c 6f 73 65 | 64 20 69 6e 20 73 69 6e |.enclose|d in sin|
|00005100| 67 6c 65 20 71 75 6f 74 | 65 73 2e 20 20 28 54 68 |gle quot|es. (Th|
|00005110| 65 20 7b 5c 74 74 20 70 | 72 69 6e 74 7d 20 73 74 |e {\tt p|rint} st|
|00005120| 61 74 65 6d 65 6e 74 2c | 20 64 65 73 63 72 69 62 |atement,| describ|
|00005130| 65 64 20 6c 61 74 65 72 | 2c 0a 63 61 6e 20 62 65 |ed later|,.can be|
|00005140| 20 75 73 65 64 20 74 6f | 20 77 72 69 74 65 20 73 | used to| write s|
|00005150| 74 72 69 6e 67 73 20 77 | 69 74 68 6f 75 74 20 71 |trings w|ithout q|
|00005160| 75 6f 74 65 73 20 6f 72 | 20 65 73 63 61 70 65 73 |uotes or| escapes|
|00005170| 2e 29 0a 0a 53 74 72 69 | 6e 67 73 20 63 61 6e 20 |.)..Stri|ngs can |
|00005180| 62 65 20 63 6f 6e 63 61 | 74 65 6e 61 74 65 64 20 |be conca|tenated |
|00005190| 28 67 6c 75 65 64 20 74 | 6f 67 65 74 68 65 72 29 |(glued t|ogether)|
|000051a0| 20 77 69 74 68 20 74 68 | 65 20 7b 5c 74 74 20 2b | with th|e {\tt +|
|000051b0| 7d 0a 6f 70 65 72 61 74 | 6f 72 2c 20 61 6e 64 20 |}.operat|or, and |
|000051c0| 72 65 70 65 61 74 65 64 | 20 77 69 74 68 20 7b 5c |repeated| with {\|
|000051d0| 74 74 20 2a 7d 3a 0a 0a | 5c 62 63 6f 64 65 5c 62 |tt *}:..|\bcode\b|
|000051e0| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 3e |egin{ver|batim}.>|
|000051f0| 3e 3e 20 77 6f 72 64 20 | 3d 20 27 48 65 6c 70 27 |>> word |= 'Help'|
|00005200| 20 2b 20 27 41 27 0a 3e | 3e 3e 20 77 6f 72 64 0a | + 'A'.>|>> word.|
|00005210| 27 48 65 6c 70 41 27 0a | 3e 3e 3e 20 27 3c 27 20 |'HelpA'.|>>> '<' |
|00005220| 2b 20 77 6f 72 64 2a 35 | 20 2b 20 27 3e 27 0a 27 |+ word*5| + '>'.'|
|00005230| 3c 48 65 6c 70 41 48 65 | 6c 70 41 48 65 6c 70 41 |<HelpAHe|lpAHelpA|
|00005240| 48 65 6c 70 41 48 65 6c | 70 41 3e 27 0a 3e 3e 3e |HelpAHel|pA>'.>>>|
|00005250| 20 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d | .\end{v|erbatim}|
|00005260| 5c 65 63 6f 64 65 0a 25 | 0a 53 74 72 69 6e 67 73 |\ecode.%|.Strings|
|00005270| 20 63 61 6e 20 62 65 20 | 73 75 62 73 63 72 69 70 | can be |subscrip|
|00005280| 74 65 64 20 28 69 6e 64 | 65 78 65 64 29 3b 20 6c |ted (ind|exed); l|
|00005290| 69 6b 65 20 69 6e 20 43 | 2c 20 74 68 65 20 66 69 |ike in C|, the fi|
|000052a0| 72 73 74 20 63 68 61 72 | 61 63 74 65 72 20 6f 66 |rst char|acter of|
|000052b0| 0a 61 20 73 74 72 69 6e | 67 20 68 61 73 20 73 75 |.a strin|g has su|
|000052c0| 62 73 63 72 69 70 74 20 | 28 69 6e 64 65 78 29 20 |bscript |(index) |
|000052d0| 30 2e 0a 0a 54 68 65 72 | 65 20 69 73 20 6e 6f 20 |0...Ther|e is no |
|000052e0| 73 65 70 61 72 61 74 65 | 20 63 68 61 72 61 63 74 |separate| charact|
|000052f0| 65 72 20 74 79 70 65 3b | 20 61 20 63 68 61 72 61 |er type;| a chara|
|00005300| 63 74 65 72 20 69 73 20 | 73 69 6d 70 6c 79 20 61 |cter is |simply a|
|00005310| 20 73 74 72 69 6e 67 20 | 6f 66 0a 73 69 7a 65 20 | string |of.size |
|00005320| 6f 6e 65 2e 20 20 4c 69 | 6b 65 20 69 6e 20 49 63 |one. Li|ke in Ic|
|00005330| 6f 6e 2c 20 73 75 62 73 | 74 72 69 6e 67 73 20 63 |on, subs|trings c|
|00005340| 61 6e 20 62 65 20 73 70 | 65 63 69 66 69 65 64 20 |an be sp|ecified |
|00005350| 77 69 74 68 20 74 68 65 | 20 7b 5c 65 6d 0a 73 6c |with the| {\em.sl|
|00005360| 69 63 65 7d 20 6e 6f 74 | 61 74 69 6f 6e 3a 20 74 |ice} not|ation: t|
|00005370| 77 6f 20 69 6e 64 69 63 | 65 73 20 73 65 70 61 72 |wo indic|es separ|
|00005380| 61 74 65 64 20 62 79 20 | 61 20 63 6f 6c 6f 6e 2e |ated by |a colon.|
|00005390| 0a 0a 5c 62 63 6f 64 65 | 5c 62 65 67 69 6e 7b 76 |..\bcode|\begin{v|
|000053a0| 65 72 62 61 74 69 6d 7d | 0a 3e 3e 3e 20 77 6f 72 |erbatim}|.>>> wor|
|000053b0| 64 5b 34 5d 0a 27 41 27 | 0a 3e 3e 3e 20 77 6f 72 |d[4].'A'|.>>> wor|
|000053c0| 64 5b 30 3a 32 5d 0a 27 | 48 65 27 0a 3e 3e 3e 20 |d[0:2].'|He'.>>> |
|000053d0| 77 6f 72 64 5b 32 3a 34 | 5d 0a 27 6c 70 27 0a 3e |word[2:4|].'lp'.>|
|000053e0| 3e 3e 20 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |>> .\end|{verbati|
|000053f0| 6d 7d 5c 65 63 6f 64 65 | 0a 25 0a 53 6c 69 63 65 |m}\ecode|.%.Slice|
|00005400| 20 69 6e 64 69 63 65 73 | 20 68 61 76 65 20 75 73 | indices| have us|
|00005410| 65 66 75 6c 20 64 65 66 | 61 75 6c 74 73 3b 20 61 |eful def|aults; a|
|00005420| 6e 20 6f 6d 69 74 74 65 | 64 20 66 69 72 73 74 20 |n omitte|d first |
|00005430| 69 6e 64 65 78 20 64 65 | 66 61 75 6c 74 73 20 74 |index de|faults t|
|00005440| 6f 0a 7a 65 72 6f 2c 20 | 61 6e 20 6f 6d 69 74 74 |o.zero, |an omitt|
|00005450| 65 64 20 73 65 63 6f 6e | 64 20 69 6e 64 65 78 20 |ed secon|d index |
|00005460| 64 65 66 61 75 6c 74 73 | 20 74 6f 20 74 68 65 20 |defaults| to the |
|00005470| 73 69 7a 65 20 6f 66 20 | 74 68 65 20 73 74 72 69 |size of |the stri|
|00005480| 6e 67 20 62 65 69 6e 67 | 0a 73 6c 69 63 65 64 2e |ng being|.sliced.|
|00005490| 0a 0a 5c 62 63 6f 64 65 | 5c 62 65 67 69 6e 7b 76 |..\bcode|\begin{v|
|000054a0| 65 72 62 61 74 69 6d 7d | 0a 3e 3e 3e 20 77 6f 72 |erbatim}|.>>> wor|
|000054b0| 64 5b 3a 32 5d 20 20 20 | 20 23 20 54 68 65 20 66 |d[:2] | # The f|
|000054c0| 69 72 73 74 20 74 77 6f | 20 63 68 61 72 61 63 74 |irst two| charact|
|000054d0| 65 72 73 0a 27 48 65 27 | 0a 3e 3e 3e 20 77 6f 72 |ers.'He'|.>>> wor|
|000054e0| 64 5b 32 3a 5d 20 20 20 | 20 23 20 41 6c 6c 20 62 |d[2:] | # All b|
|000054f0| 75 74 20 74 68 65 20 66 | 69 72 73 74 20 74 77 6f |ut the f|irst two|
|00005500| 20 63 68 61 72 61 63 74 | 65 72 73 0a 27 6c 70 41 | charact|ers.'lpA|
|00005510| 27 0a 3e 3e 3e 0a 5c 65 | 6e 64 7b 76 65 72 62 61 |'.>>>.\e|nd{verba|
|00005520| 74 69 6d 7d 5c 65 63 6f | 64 65 0a 25 0a 48 65 72 |tim}\eco|de.%.Her|
|00005530| 65 27 73 20 61 20 75 73 | 65 66 75 6c 20 69 6e 76 |e's a us|eful inv|
|00005540| 61 72 69 61 6e 74 20 6f | 66 20 73 6c 69 63 65 20 |ariant o|f slice |
|00005550| 6f 70 65 72 61 74 69 6f | 6e 73 3a 20 5c 76 65 72 |operatio|ns: \ver|
|00005560| 62 5c 73 5b 3a 69 5d 20 | 2b 20 73 5b 69 3a 5d 5c |b\s[:i] |+ s[i:]\|
|00005570| 0a 65 71 75 61 6c 73 20 | 5c 76 65 72 62 5c 73 5c |.equals |\verb\s\|
|00005580| 2e 0a 0a 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |...\bcod|e\begin{|
|00005590| 76 65 72 62 61 74 69 6d | 7d 0a 3e 3e 3e 20 77 6f |verbatim|}.>>> wo|
|000055a0| 72 64 5b 3a 32 5d 20 2b | 20 77 6f 72 64 5b 32 3a |rd[:2] +| word[2:|
|000055b0| 5d 0a 27 48 65 6c 70 41 | 27 0a 3e 3e 3e 20 77 6f |].'HelpA|'.>>> wo|
|000055c0| 72 64 5b 3a 33 5d 20 2b | 20 77 6f 72 64 5b 33 3a |rd[:3] +| word[3:|
|000055d0| 5d 0a 27 48 65 6c 70 41 | 27 0a 3e 3e 3e 20 0a 5c |].'HelpA|'.>>> .\|
|000055e0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 5c 65 63 |end{verb|atim}\ec|
|000055f0| 6f 64 65 0a 25 0a 44 65 | 67 65 6e 65 72 61 74 65 |ode.%.De|generate|
|00005600| 20 73 6c 69 63 65 20 69 | 6e 64 69 63 65 73 20 61 | slice i|ndices a|
|00005610| 72 65 20 68 61 6e 64 6c | 65 64 20 67 72 61 63 65 |re handl|ed grace|
|00005620| 66 75 6c 6c 79 3a 20 61 | 6e 20 69 6e 64 65 78 20 |fully: a|n index |
|00005630| 74 68 61 74 20 69 73 20 | 74 6f 6f 0a 6c 61 72 67 |that is |too.larg|
|00005640| 65 20 69 73 20 72 65 70 | 6c 61 63 65 64 20 62 79 |e is rep|laced by|
|00005650| 20 74 68 65 20 73 74 72 | 69 6e 67 20 73 69 7a 65 | the str|ing size|
|00005660| 2c 20 61 6e 20 75 70 70 | 65 72 20 62 6f 75 6e 64 |, an upp|er bound|
|00005670| 20 73 6d 61 6c 6c 65 72 | 20 74 68 61 6e 20 74 68 | smaller| than th|
|00005680| 65 0a 6c 6f 77 65 72 20 | 62 6f 75 6e 64 20 72 65 |e.lower |bound re|
|00005690| 74 75 72 6e 73 20 61 6e | 20 65 6d 70 74 79 20 73 |turns an| empty s|
|000056a0| 74 72 69 6e 67 2e 0a 0a | 5c 62 63 6f 64 65 5c 62 |tring...|\bcode\b|
|000056b0| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 3e |egin{ver|batim}.>|
|000056c0| 3e 3e 20 77 6f 72 64 5b | 31 3a 31 30 30 5d 0a 27 |>> word[|1:100].'|
|000056d0| 65 6c 70 41 27 0a 3e 3e | 3e 20 77 6f 72 64 5b 31 |elpA'.>>|> word[1|
|000056e0| 30 3a 5d 0a 27 27 0a 3e | 3e 3e 20 77 6f 72 64 5b |0:].''.>|>> word[|
|000056f0| 32 3a 31 5d 0a 27 27 0a | 3e 3e 3e 20 0a 5c 65 6e |2:1].''.|>>> .\en|
|00005700| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00005710| 65 0a 25 0a 49 6e 64 69 | 63 65 73 20 6d 61 79 20 |e.%.Indi|ces may |
|00005720| 62 65 20 6e 65 67 61 74 | 69 76 65 20 6e 75 6d 62 |be negat|ive numb|
|00005730| 65 72 73 2c 20 74 6f 20 | 73 74 61 72 74 20 63 6f |ers, to |start co|
|00005740| 75 6e 74 69 6e 67 20 66 | 72 6f 6d 20 74 68 65 20 |unting f|rom the |
|00005750| 72 69 67 68 74 2e 0a 46 | 6f 72 20 65 78 61 6d 70 |right..F|or examp|
|00005760| 6c 65 3a 0a 0a 5c 62 63 | 6f 64 65 5c 62 65 67 69 |le:..\bc|ode\begi|
|00005770| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0a 3e 3e 3e 20 |n{verbat|im}.>>> |
|00005780| 77 6f 72 64 5b 2d 31 5d | 20 20 20 20 20 23 20 54 |word[-1]| # T|
|00005790| 68 65 20 6c 61 73 74 20 | 63 68 61 72 61 63 74 65 |he last |characte|
|000057a0| 72 0a 27 41 27 0a 3e 3e | 3e 20 77 6f 72 64 5b 2d |r.'A'.>>|> word[-|
|000057b0| 32 5d 20 20 20 20 20 23 | 20 54 68 65 20 6c 61 73 |2] #| The las|
|000057c0| 74 2d 62 75 74 2d 6f 6e | 65 20 63 68 61 72 61 63 |t-but-on|e charac|
|000057d0| 74 65 72 0a 27 70 27 0a | 3e 3e 3e 20 77 6f 72 64 |ter.'p'.|>>> word|
|000057e0| 5b 2d 32 3a 5d 20 20 20 | 20 23 20 54 68 65 20 6c |[-2:] | # The l|
|000057f0| 61 73 74 20 74 77 6f 20 | 63 68 61 72 61 63 74 65 |ast two |characte|
|00005800| 72 73 0a 27 70 41 27 0a | 3e 3e 3e 20 77 6f 72 64 |rs.'pA'.|>>> word|
|00005810| 5b 3a 2d 32 5d 20 20 20 | 20 23 20 41 6c 6c 20 62 |[:-2] | # All b|
|00005820| 75 74 20 74 68 65 20 6c | 61 73 74 20 74 77 6f 20 |ut the l|ast two |
|00005830| 63 68 61 72 61 63 74 65 | 72 73 0a 27 48 65 6c 27 |characte|rs.'Hel'|
|00005840| 0a 3e 3e 3e 0a 5c 65 6e | 64 7b 76 65 72 62 61 74 |.>>>.\en|d{verbat|
|00005850| 69 6d 7d 5c 65 63 6f 64 | 65 0a 25 0a 42 75 74 20 |im}\ecod|e.%.But |
|00005860| 6e 6f 74 65 20 74 68 61 | 74 20 2d 30 20 69 73 20 |note tha|t -0 is |
|00005870| 72 65 61 6c 6c 79 20 74 | 68 65 20 73 61 6d 65 20 |really t|he same |
|00005880| 61 73 20 30 2c 20 73 6f | 20 69 74 20 64 6f 65 73 |as 0, so| it does|
|00005890| 20 6e 6f 74 20 63 6f 75 | 6e 74 20 66 72 6f 6d 0a | not cou|nt from.|
|000058a0| 74 68 65 20 72 69 67 68 | 74 21 0a 0a 5c 62 63 6f |the righ|t!..\bco|
|000058b0| 64 65 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |de\begin|{verbati|
|000058c0| 6d 7d 0a 3e 3e 3e 20 77 | 6f 72 64 5b 2d 30 5d 20 |m}.>>> w|ord[-0] |
|000058d0| 20 20 20 20 23 20 28 73 | 69 6e 63 65 20 2d 30 20 | # (s|ince -0 |
|000058e0| 65 71 75 61 6c 73 20 30 | 29 0a 27 48 27 0a 3e 3e |equals 0|).'H'.>>|
|000058f0| 3e 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |>.\end{v|erbatim}|
|00005900| 5c 65 63 6f 64 65 0a 25 | 0a 4f 75 74 2d 6f 66 2d |\ecode.%|.Out-of-|
|00005910| 72 61 6e 67 65 20 6e 65 | 67 61 74 69 76 65 20 73 |range ne|gative s|
|00005920| 6c 69 63 65 20 69 6e 64 | 69 63 65 73 20 61 72 65 |lice ind|ices are|
|00005930| 20 74 72 75 6e 63 61 74 | 65 64 2c 20 62 75 74 20 | truncat|ed, but |
|00005940| 64 6f 6e 27 74 20 74 72 | 79 20 74 68 69 73 0a 66 |don't tr|y this.f|
|00005950| 6f 72 20 73 69 6e 67 6c | 65 2d 65 6c 65 6d 65 6e |or singl|e-elemen|
|00005960| 74 20 28 6e 6f 6e 2d 73 | 6c 69 63 65 29 20 69 6e |t (non-s|lice) in|
|00005970| 64 69 63 65 73 3a 0a 0a | 5c 62 63 6f 64 65 5c 62 |dices:..|\bcode\b|
|00005980| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 3e |egin{ver|batim}.>|
|00005990| 3e 3e 20 77 6f 72 64 5b | 2d 31 30 30 3a 5d 0a 27 |>> word[|-100:].'|
|000059a0| 48 65 6c 70 41 27 0a 3e | 3e 3e 20 77 6f 72 64 5b |HelpA'.>|>> word[|
|000059b0| 2d 31 30 5d 20 20 20 20 | 23 20 65 72 72 6f 72 0a |-10] |# error.|
|000059c0| 54 72 61 63 65 62 61 63 | 6b 20 28 69 6e 6e 65 72 |Tracebac|k (inner|
|000059d0| 6d 6f 73 74 20 6c 61 73 | 74 29 3a 0a 20 20 46 69 |most las|t):. Fi|
|000059e0| 6c 65 20 22 3c 73 74 64 | 69 6e 3e 22 2c 20 6c 69 |le "<std|in>", li|
|000059f0| 6e 65 20 31 0a 49 6e 64 | 65 78 45 72 72 6f 72 3a |ne 1.Ind|exError:|
|00005a00| 20 73 74 72 69 6e 67 20 | 69 6e 64 65 78 20 6f 75 | string |index ou|
|00005a10| 74 20 6f 66 20 72 61 6e | 67 65 0a 3e 3e 3e 20 0a |t of ran|ge.>>> .|
|00005a20| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00005a30| 63 6f 64 65 0a 25 0a 54 | 68 65 20 62 65 73 74 20 |code.%.T|he best |
|00005a40| 77 61 79 20 74 6f 20 72 | 65 6d 65 6d 62 65 72 20 |way to r|emember |
|00005a50| 68 6f 77 20 73 6c 69 63 | 65 73 20 77 6f 72 6b 20 |how slic|es work |
|00005a60| 69 73 20 74 6f 20 74 68 | 69 6e 6b 20 6f 66 20 74 |is to th|ink of t|
|00005a70| 68 65 20 69 6e 64 69 63 | 65 73 20 61 73 0a 70 6f |he indic|es as.po|
|00005a80| 69 6e 74 69 6e 67 20 7b | 5c 65 6d 20 62 65 74 77 |inting {|\em betw|
|00005a90| 65 65 6e 7d 20 63 68 61 | 72 61 63 74 65 72 73 2c |een} cha|racters,|
|00005aa0| 20 77 69 74 68 20 74 68 | 65 20 6c 65 66 74 20 65 | with th|e left e|
|00005ab0| 64 67 65 20 6f 66 20 74 | 68 65 20 66 69 72 73 74 |dge of t|he first|
|00005ac0| 0a 63 68 61 72 61 63 74 | 65 72 20 6e 75 6d 62 65 |.charact|er numbe|
|00005ad0| 72 65 64 20 30 2e 20 20 | 54 68 65 6e 20 74 68 65 |red 0. |Then the|
|00005ae0| 20 72 69 67 68 74 20 65 | 64 67 65 20 6f 66 20 74 | right e|dge of t|
|00005af0| 68 65 20 6c 61 73 74 20 | 63 68 61 72 61 63 74 65 |he last |characte|
|00005b00| 72 20 6f 66 20 61 0a 73 | 74 72 69 6e 67 20 6f 66 |r of a.s|tring of|
|00005b10| 20 7b 5c 74 74 20 6e 7d | 20 63 68 61 72 61 63 74 | {\tt n}| charact|
|00005b20| 65 72 73 20 68 61 73 20 | 69 6e 64 65 78 20 7b 5c |ers has |index {\|
|00005b30| 74 74 20 6e 7d 2c 20 66 | 6f 72 20 65 78 61 6d 70 |tt n}, f|or examp|
|00005b40| 6c 65 3a 0a 0a 5c 62 63 | 6f 64 65 5c 62 65 67 69 |le:..\bc|ode\begi|
|00005b50| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0a 20 2b 2d 2d |n{verbat|im}. +--|
|00005b60| 2d 2b 2d 2d 2d 2b 2d 2d | 2d 2b 2d 2d 2d 2b 2d 2d |-+---+--|-+---+--|
|00005b70| 2d 2b 20 0a 20 7c 20 48 | 20 7c 20 65 20 7c 20 6c |-+ . | H| | e | l|
|00005b80| 20 7c 20 70 20 7c 20 41 | 20 7c 0a 20 2b 2d 2d 2d | | p | A| |. +---|
|00005b90| 2b 2d 2d 2d 2b 2d 2d 2d | 2b 2d 2d 2d 2b 2d 2d 2d |+---+---|+---+---|
|00005ba0| 2b 20 0a 20 30 20 20 20 | 31 20 20 20 32 20 20 20 |+ . 0 |1 2 |
|00005bb0| 33 20 20 20 34 20 20 20 | 35 20 0a 2d 35 20 20 2d |3 4 |5 .-5 -|
|00005bc0| 34 20 20 2d 33 20 20 2d | 32 20 20 2d 31 0a 5c 65 |4 -3 -|2 -1.\e|
|00005bd0| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 5c 65 63 6f |nd{verba|tim}\eco|
|00005be0| 64 65 0a 25 0a 54 68 65 | 20 66 69 72 73 74 20 72 |de.%.The| first r|
|00005bf0| 6f 77 20 6f 66 20 6e 75 | 6d 62 65 72 73 20 67 69 |ow of nu|mbers gi|
|00005c00| 76 65 73 20 74 68 65 20 | 70 6f 73 69 74 69 6f 6e |ves the |position|
|00005c10| 20 6f 66 20 74 68 65 20 | 69 6e 64 69 63 65 73 20 | of the |indices |
|00005c20| 30 2e 2e 2e 35 20 69 6e | 0a 74 68 65 20 73 74 72 |0...5 in|.the str|
|00005c30| 69 6e 67 3b 20 74 68 65 | 20 73 65 63 6f 6e 64 20 |ing; the| second |
|00005c40| 72 6f 77 20 67 69 76 65 | 73 20 74 68 65 20 63 6f |row give|s the co|
|00005c50| 72 72 65 73 70 6f 6e 64 | 69 6e 67 20 6e 65 67 61 |rrespond|ing nega|
|00005c60| 74 69 76 65 20 69 6e 64 | 69 63 65 73 2e 0a 54 68 |tive ind|ices..Th|
|00005c70| 65 20 73 6c 69 63 65 20 | 66 72 6f 6d 20 5c 76 65 |e slice |from \ve|
|00005c80| 72 62 5c 69 5c 20 74 6f | 20 5c 76 65 72 62 5c 6a |rb\i\ to| \verb\j|
|00005c90| 5c 20 63 6f 6e 73 69 73 | 74 73 20 6f 66 20 61 6c |\ consis|ts of al|
|00005ca0| 6c 20 63 68 61 72 61 63 | 74 65 72 73 20 62 65 74 |l charac|ters bet|
|00005cb0| 77 65 65 6e 0a 74 68 65 | 20 65 64 67 65 73 20 6c |ween.the| edges l|
|00005cc0| 61 62 65 6c 65 64 20 5c | 76 65 72 62 5c 69 5c 20 |abeled \|verb\i\ |
|00005cd0| 61 6e 64 20 5c 76 65 72 | 62 5c 6a 5c 2c 20 72 65 |and \ver|b\j\, re|
|00005ce0| 73 70 65 63 74 69 76 65 | 6c 79 2e 0a 0a 46 6f 72 |spective|ly...For|
|00005cf0| 20 6e 6f 6e 6e 65 67 61 | 74 69 76 65 20 69 6e 64 | nonnega|tive ind|
|00005d00| 69 63 65 73 2c 20 74 68 | 65 20 6c 65 6e 67 74 68 |ices, th|e length|
|00005d10| 20 6f 66 20 61 20 73 6c | 69 63 65 20 69 73 20 74 | of a sl|ice is t|
|00005d20| 68 65 20 64 69 66 66 65 | 72 65 6e 63 65 20 6f 66 |he diffe|rence of|
|00005d30| 0a 74 68 65 20 69 6e 64 | 69 63 65 73 2c 20 69 66 |.the ind|ices, if|
|00005d40| 20 62 6f 74 68 20 61 72 | 65 20 77 69 74 68 69 6e | both ar|e within|
|00005d50| 20 62 6f 75 6e 64 73 2c | 20 65 2e 67 2e 2c 20 74 | bounds,| e.g., t|
|00005d60| 68 65 20 6c 65 6e 67 74 | 68 20 6f 66 0a 5c 76 65 |he lengt|h of.\ve|
|00005d70| 72 62 5c 77 6f 72 64 5b | 31 3a 33 5d 5c 20 69 73 |rb\word[|1:3]\ is|
|00005d80| 20 32 2e 0a 0a 54 68 65 | 20 62 75 69 6c 74 2d 69 | 2...The| built-i|
|00005d90| 6e 20 66 75 6e 63 74 69 | 6f 6e 20 7b 5c 74 74 20 |n functi|on {\tt |
|00005da0| 6c 65 6e 28 29 7d 20 72 | 65 74 75 72 6e 73 20 74 |len()} r|eturns t|
|00005db0| 68 65 20 6c 65 6e 67 74 | 68 20 6f 66 20 61 20 73 |he lengt|h of a s|
|00005dc0| 74 72 69 6e 67 3a 0a 0a | 5c 62 63 6f 64 65 5c 62 |tring:..|\bcode\b|
|00005dd0| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 3e |egin{ver|batim}.>|
|00005de0| 3e 3e 20 73 20 3d 20 27 | 73 75 70 65 72 63 61 6c |>> s = '|supercal|
|00005df0| 69 66 72 61 67 69 6c 69 | 73 74 69 63 65 78 70 69 |ifragili|sticexpi|
|00005e00| 61 6c 69 64 6f 63 69 6f | 75 73 27 0a 3e 3e 3e 20 |alidocio|us'.>>> |
|00005e10| 6c 65 6e 28 73 29 0a 33 | 34 0a 3e 3e 3e 20 0a 5c |len(s).3|4.>>> .\|
|00005e20| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 5c 65 63 |end{verb|atim}\ec|
|00005e30| 6f 64 65 0a 0a 5c 73 75 | 62 73 65 63 74 69 6f 6e |ode..\su|bsection|
|00005e40| 7b 4c 69 73 74 73 7d 0a | 0a 50 79 74 68 6f 6e 20 |{Lists}.|.Python |
|00005e50| 6b 6e 6f 77 73 20 61 20 | 6e 75 6d 62 65 72 20 6f |knows a |number o|
|00005e60| 66 20 7b 5c 65 6d 20 63 | 6f 6d 70 6f 75 6e 64 7d |f {\em c|ompound}|
|00005e70| 20 64 61 74 61 20 74 79 | 70 65 73 2c 20 75 73 65 | data ty|pes, use|
|00005e80| 64 20 74 6f 20 67 72 6f | 75 70 0a 74 6f 67 65 74 |d to gro|up.toget|
|00005e90| 68 65 72 20 6f 74 68 65 | 72 20 76 61 6c 75 65 73 |her othe|r values|
|00005ea0| 2e 20 20 54 68 65 20 6d | 6f 73 74 20 76 65 72 73 |. The m|ost vers|
|00005eb0| 61 74 69 6c 65 20 69 73 | 20 74 68 65 20 7b 5c 65 |atile is| the {\e|
|00005ec0| 6d 20 6c 69 73 74 7d 2c | 20 77 68 69 63 68 0a 63 |m list},| which.c|
|00005ed0| 61 6e 20 62 65 20 77 72 | 69 74 74 65 6e 20 61 73 |an be wr|itten as|
|00005ee0| 20 61 20 6c 69 73 74 20 | 6f 66 20 63 6f 6d 6d 61 | a list |of comma|
|00005ef0| 2d 73 65 70 61 72 61 74 | 65 64 20 76 61 6c 75 65 |-separat|ed value|
|00005f00| 73 20 28 69 74 65 6d 73 | 29 20 62 65 74 77 65 65 |s (items|) betwee|
|00005f10| 6e 0a 73 71 75 61 72 65 | 20 62 72 61 63 6b 65 74 |n.square| bracket|
|00005f20| 73 2e 20 20 4c 69 73 74 | 20 69 74 65 6d 73 20 6e |s. List| items n|
|00005f30| 65 65 64 20 6e 6f 74 20 | 61 6c 6c 20 68 61 76 65 |eed not |all have|
|00005f40| 20 74 68 65 20 73 61 6d | 65 20 74 79 70 65 2e 0a | the sam|e type..|
|00005f50| 0a 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|00005f60| 72 62 61 74 69 6d 7d 0a | 3e 3e 3e 20 61 20 3d 20 |rbatim}.|>>> a = |
|00005f70| 5b 27 73 70 61 6d 27 2c | 20 27 65 67 67 73 27 2c |['spam',| 'eggs',|
|00005f80| 20 31 30 30 2c 20 31 32 | 33 34 5d 0a 3e 3e 3e 20 | 100, 12|34].>>> |
|00005f90| 61 0a 5b 27 73 70 61 6d | 27 2c 20 27 65 67 67 73 |a.['spam|', 'eggs|
|00005fa0| 27 2c 20 31 30 30 2c 20 | 31 32 33 34 5d 0a 3e 3e |', 100, |1234].>>|
|00005fb0| 3e 20 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |> .\end{|verbatim|
|00005fc0| 7d 5c 65 63 6f 64 65 0a | 25 0a 4c 69 6b 65 20 73 |}\ecode.|%.Like s|
|00005fd0| 74 72 69 6e 67 20 69 6e | 64 69 63 65 73 2c 20 6c |tring in|dices, l|
|00005fe0| 69 73 74 20 69 6e 64 69 | 63 65 73 20 73 74 61 72 |ist indi|ces star|
|00005ff0| 74 20 61 74 20 30 2c 20 | 61 6e 64 20 6c 69 73 74 |t at 0, |and list|
|00006000| 73 20 63 61 6e 20 62 65 | 20 73 6c 69 63 65 64 2c |s can be| sliced,|
|00006010| 0a 63 6f 6e 63 61 74 65 | 6e 61 74 65 64 20 61 6e |.concate|nated an|
|00006020| 64 20 73 6f 20 6f 6e 3a | 0a 0a 5c 62 63 6f 64 65 |d so on:|..\bcode|
|00006030| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00006040| 0a 3e 3e 3e 20 61 5b 30 | 5d 0a 27 73 70 61 6d 27 |.>>> a[0|].'spam'|
|00006050| 0a 3e 3e 3e 20 61 5b 33 | 5d 0a 31 32 33 34 0a 3e |.>>> a[3|].1234.>|
|00006060| 3e 3e 20 61 5b 2d 32 5d | 0a 31 30 30 0a 3e 3e 3e |>> a[-2]|.100.>>>|
|00006070| 20 61 5b 31 3a 2d 31 5d | 0a 5b 27 65 67 67 73 27 | a[1:-1]|.['eggs'|
|00006080| 2c 20 31 30 30 5d 0a 3e | 3e 3e 20 61 5b 3a 32 5d |, 100].>|>> a[:2]|
|00006090| 20 2b 20 5b 27 62 61 63 | 6f 6e 27 2c 20 32 2a 32 | + ['bac|on', 2*2|
|000060a0| 5d 0a 5b 27 73 70 61 6d | 27 2c 20 27 65 67 67 73 |].['spam|', 'eggs|
|000060b0| 27 2c 20 27 62 61 63 6f | 6e 27 2c 20 34 5d 0a 3e |', 'baco|n', 4].>|
|000060c0| 3e 3e 20 33 2a 61 5b 3a | 33 5d 20 2b 20 5b 27 42 |>> 3*a[:|3] + ['B|
|000060d0| 6f 65 21 27 5d 0a 5b 27 | 73 70 61 6d 27 2c 20 27 |oe!'].['|spam', '|
|000060e0| 65 67 67 73 27 2c 20 31 | 30 30 2c 20 27 73 70 61 |eggs', 1|00, 'spa|
|000060f0| 6d 27 2c 20 27 65 67 67 | 73 27 2c 20 31 30 30 2c |m', 'egg|s', 100,|
|00006100| 20 27 73 70 61 6d 27 2c | 20 27 65 67 67 73 27 2c | 'spam',| 'eggs',|
|00006110| 20 31 30 30 2c 20 27 42 | 6f 65 21 27 5d 0a 3e 3e | 100, 'B|oe!'].>>|
|00006120| 3e 20 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |> .\end{|verbatim|
|00006130| 7d 5c 65 63 6f 64 65 0a | 25 0a 55 6e 6c 69 6b 65 |}\ecode.|%.Unlike|
|00006140| 20 73 74 72 69 6e 67 73 | 2c 20 77 68 69 63 68 20 | strings|, which |
|00006150| 61 72 65 20 7b 5c 65 6d | 20 69 6d 6d 75 74 61 62 |are {\em| immutab|
|00006160| 6c 65 7d 2c 20 69 74 20 | 69 73 20 70 6f 73 73 69 |le}, it |is possi|
|00006170| 62 6c 65 20 74 6f 20 63 | 68 61 6e 67 65 0a 69 6e |ble to c|hange.in|
|00006180| 64 69 76 69 64 75 61 6c | 20 65 6c 65 6d 65 6e 74 |dividual| element|
|00006190| 73 20 6f 66 20 61 20 6c | 69 73 74 3a 0a 0a 5c 62 |s of a l|ist:..\b|
|000061a0| 63 6f 64 65 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |code\beg|in{verba|
|000061b0| 74 69 6d 7d 0a 3e 3e 3e | 20 61 0a 5b 27 73 70 61 |tim}.>>>| a.['spa|
|000061c0| 6d 27 2c 20 27 65 67 67 | 73 27 2c 20 31 30 30 2c |m', 'egg|s', 100,|
|000061d0| 20 31 32 33 34 5d 0a 3e | 3e 3e 20 61 5b 32 5d 20 | 1234].>|>> a[2] |
|000061e0| 3d 20 61 5b 32 5d 20 2b | 20 32 33 0a 3e 3e 3e 20 |= a[2] +| 23.>>> |
|000061f0| 61 0a 5b 27 73 70 61 6d | 27 2c 20 27 65 67 67 73 |a.['spam|', 'eggs|
|00006200| 27 2c 20 31 32 33 2c 20 | 31 32 33 34 5d 0a 3e 3e |', 123, |1234].>>|
|00006210| 3e 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |>.\end{v|erbatim}|
|00006220| 5c 65 63 6f 64 65 0a 25 | 0a 41 73 73 69 67 6e 6d |\ecode.%|.Assignm|
|00006230| 65 6e 74 20 74 6f 20 73 | 6c 69 63 65 73 20 69 73 |ent to s|lices is|
|00006240| 20 61 6c 73 6f 20 70 6f | 73 73 69 62 6c 65 2c 20 | also po|ssible, |
|00006250| 61 6e 64 20 74 68 69 73 | 20 63 61 6e 20 65 76 65 |and this| can eve|
|00006260| 6e 20 63 68 61 6e 67 65 | 20 74 68 65 20 73 69 7a |n change| the siz|
|00006270| 65 0a 6f 66 20 74 68 65 | 20 6c 69 73 74 3a 0a 0a |e.of the| list:..|
|00006280| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00006290| 62 61 74 69 6d 7d 0a 3e | 3e 3e 20 23 20 52 65 70 |batim}.>|>> # Rep|
|000062a0| 6c 61 63 65 20 73 6f 6d | 65 20 69 74 65 6d 73 3a |lace som|e items:|
|000062b0| 0a 2e 2e 2e 20 61 5b 30 | 3a 32 5d 20 3d 20 5b 31 |.... a[0|:2] = [1|
|000062c0| 2c 20 31 32 5d 0a 3e 3e | 3e 20 61 0a 5b 31 2c 20 |, 12].>>|> a.[1, |
|000062d0| 31 32 2c 20 31 32 33 2c | 20 31 32 33 34 5d 0a 3e |12, 123,| 1234].>|
|000062e0| 3e 3e 20 23 20 52 65 6d | 6f 76 65 20 73 6f 6d 65 |>> # Rem|ove some|
|000062f0| 3a 0a 2e 2e 2e 20 61 5b | 30 3a 32 5d 20 3d 20 5b |:.... a[|0:2] = [|
|00006300| 5d 0a 3e 3e 3e 20 61 0a | 5b 31 32 33 2c 20 31 32 |].>>> a.|[123, 12|
|00006310| 33 34 5d 0a 3e 3e 3e 20 | 23 20 49 6e 73 65 72 74 |34].>>> |# Insert|
|00006320| 20 73 6f 6d 65 3a 0a 2e | 2e 2e 20 61 5b 31 3a 31 | some:..|.. a[1:1|
|00006330| 5d 20 3d 20 5b 27 62 6c | 65 74 63 68 27 2c 20 27 |] = ['bl|etch', '|
|00006340| 78 79 7a 7a 79 27 5d 0a | 3e 3e 3e 20 61 0a 5b 31 |xyzzy'].|>>> a.[1|
|00006350| 32 33 2c 20 27 62 6c 65 | 74 63 68 27 2c 20 27 78 |23, 'ble|tch', 'x|
|00006360| 79 7a 7a 79 27 2c 20 31 | 32 33 34 5d 0a 3e 3e 3e |yzzy', 1|234].>>>|
|00006370| 20 61 5b 3a 30 5d 20 3d | 20 61 20 20 20 20 20 23 | a[:0] =| a #|
|00006380| 20 49 6e 73 65 72 74 20 | 28 61 20 63 6f 70 79 20 | Insert |(a copy |
|00006390| 6f 66 29 20 69 74 73 65 | 6c 66 20 61 74 20 74 68 |of) itse|lf at th|
|000063a0| 65 20 62 65 67 69 6e 6e | 69 6e 67 0a 3e 3e 3e 20 |e beginn|ing.>>> |
|000063b0| 61 0a 5b 31 32 33 2c 20 | 27 62 6c 65 74 63 68 27 |a.[123, |'bletch'|
|000063c0| 2c 20 27 78 79 7a 7a 79 | 27 2c 20 31 32 33 34 2c |, 'xyzzy|', 1234,|
|000063d0| 20 31 32 33 2c 20 27 62 | 6c 65 74 63 68 27 2c 20 | 123, 'b|letch', |
|000063e0| 27 78 79 7a 7a 79 27 2c | 20 31 32 33 34 5d 0a 3e |'xyzzy',| 1234].>|
|000063f0| 3e 3e 20 0a 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |>> .\end|{verbati|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.