home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Doc / tut.tex < prev    next >
LaTeX Document  |  1994-10-06  |  108.1 KB  |  [TEXT/R*ch]

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: tut.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, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



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 0d 0d 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 0d 0d | 5c 69 6e 70 75 74 7b 62 |orial}..|\input{b|
|00000050| 6f 69 6c 65 72 70 6c 61 | 74 65 7d 0d 0d 5c 62 65 |oilerpla|te}..\be|
|00000060| 67 69 6e 7b 64 6f 63 75 | 6d 65 6e 74 7d 0d 0d 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 0d 0d 5c 6d | 61 6b 65 74 69 74 6c 65 |man}..\m|aketitle|
|00000090| 0d 0d 5c 69 6e 70 75 74 | 7b 63 6f 70 79 72 69 67 |..\input|{copyrig|
|000000a0| 68 74 7d 0d 0d 5c 62 65 | 67 69 6e 7b 61 62 73 74 |ht}..\be|gin{abst|
|000000b0| 72 61 63 74 7d 0d 0d 5c | 6e 6f 69 6e 64 65 6e 74 |ract}..\|noindent|
|000000c0| 0d 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 0d | 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 0d 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 0d 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| 0d 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 0d 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 0d 0d 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 0d 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 0d 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 0d 77 | as edit|ors or.w|
|000002e0| 69 6e 64 6f 77 20 6d 61 | 6e 61 67 65 72 73 2e 0d |indow ma|nagers..|
|000002f0| 0d 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 0d 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 41 6d |s of {\U|NIX}, Am|
|00000350| 6f 65 62 61 2c 20 74 68 | 65 20 41 70 70 6c 65 20 |oeba, th|e Apple |
|00000360| 4d 61 63 69 6e 74 6f 73 | 68 20 4f 2e 53 2e 2c 0d |Macintos|h O.S.,.|
|00000370| 61 6e 64 20 4d 53 2d 44 | 4f 53 2e 0d 0d 54 68 69 |and MS-D|OS...Thi|
|00000380| 73 20 74 75 74 6f 72 69 | 61 6c 20 69 6e 74 72 6f |s tutori|al intro|
|00000390| 64 75 63 65 73 20 74 68 | 65 20 72 65 61 64 65 72 |duces th|e reader|
|000003a0| 20 69 6e 66 6f 72 6d 61 | 6c 6c 79 20 74 6f 20 74 | informa|lly to t|
|000003b0| 68 65 20 62 61 73 69 63 | 20 63 6f 6e 63 65 70 74 |he basic| concept|
|000003c0| 73 0d 61 6e 64 20 66 65 | 61 74 75 72 65 73 20 6f |s.and fe|atures o|
|000003d0| 66 20 74 68 65 20 50 79 | 74 68 6f 6e 20 6c 61 6e |f the Py|thon lan|
|000003e0| 67 75 61 67 65 20 61 6e | 64 20 73 79 73 74 65 6d |guage an|d system|
|000003f0| 2e 20 20 49 74 20 68 65 | 6c 70 73 20 74 6f 20 68 |. It he|lps to h|
|00000400| 61 76 65 20 61 0d 50 79 | 74 68 6f 6e 20 69 6e 74 |ave a.Py|thon int|
|00000410| 65 72 70 72 65 74 65 72 | 20 68 61 6e 64 79 20 66 |erpreter| handy f|
|00000420| 6f 72 20 68 61 6e 64 73 | 2d 6f 6e 20 65 78 70 65 |or hands|-on expe|
|00000430| 72 69 65 6e 63 65 2c 20 | 62 75 74 20 61 73 20 74 |rience, |but as t|
|00000440| 68 65 20 65 78 61 6d 70 | 6c 65 73 0d 61 72 65 20 |he examp|les.are |
|00000450| 73 65 6c 66 2d 63 6f 6e | 74 61 69 6e 65 64 2c 20 |self-con|tained, |
|00000460| 74 68 65 20 74 75 74 6f | 72 69 61 6c 20 63 61 6e |the tuto|rial can|
|00000470| 20 62 65 20 72 65 61 64 | 20 6f 66 66 2d 6c 69 6e | be read| off-lin|
|00000480| 65 20 61 73 20 77 65 6c | 6c 2e 0d 0d 46 6f 72 20 |e as wel|l...For |
|00000490| 61 20 64 65 73 63 72 69 | 70 74 69 6f 6e 20 6f 66 |a descri|ption of|
|000004a0| 20 73 74 61 6e 64 61 72 | 64 20 6f 62 6a 65 63 74 | standar|d object|
|000004b0| 73 20 61 6e 64 20 6d 6f | 64 75 6c 65 73 2c 20 73 |s and mo|dules, s|
|000004c0| 65 65 20 74 68 65 20 7b | 5c 65 6d 20 50 79 74 68 |ee the {|\em Pyth|
|000004d0| 6f 6e 0d 4c 69 62 72 61 | 72 79 20 52 65 66 65 72 |on.Libra|ry Refer|
|000004e0| 65 6e 63 65 7d 20 64 6f | 63 75 6d 65 6e 74 2e 20 |ence} do|cument. |
|000004f0| 20 54 68 65 20 7b 5c 65 | 6d 20 50 79 74 68 6f 6e | The {\e|m Python|
|00000500| 20 52 65 66 65 72 65 6e | 63 65 20 4d 61 6e 75 61 | Referen|ce Manua|
|00000510| 6c 7d 20 67 69 76 65 73 | 0d 61 20 6d 6f 72 65 20 |l} gives|.a more |
|00000520| 66 6f 72 6d 61 6c 20 64 | 65 66 69 6e 69 74 69 6f |formal d|efinitio|
|00000530| 6e 20 6f 66 20 74 68 65 | 20 6c 61 6e 67 75 61 67 |n of the| languag|
|00000540| 65 2e 0d 0d 5c 65 6e 64 | 7b 61 62 73 74 72 61 63 |e...\end|{abstrac|
|00000550| 74 7d 0d 0d 5c 70 61 67 | 65 62 72 65 61 6b 0d 7b |t}..\pag|ebreak.{|
|00000560| 0d 5c 70 61 72 73 6b 69 | 70 20 3d 20 30 6d 6d 0d |.\parski|p = 0mm.|
|00000570| 5c 74 61 62 6c 65 6f 66 | 63 6f 6e 74 65 6e 74 73 |\tableof|contents|
|00000580| 0d 7d 0d 0d 5c 70 61 67 | 65 62 72 65 61 6b 0d 0d |.}..\pag|ebreak..|
|00000590| 5c 70 61 67 65 6e 75 6d | 62 65 72 69 6e 67 7b 61 |\pagenum|bering{a|
|000005a0| 72 61 62 69 63 7d 0d 0d | 0d 5c 63 68 61 70 74 65 |rabic}..|.\chapte|
|000005b0| 72 7b 57 68 65 74 74 69 | 6e 67 20 59 6f 75 72 20 |r{Whetti|ng Your |
|000005c0| 41 70 70 65 74 69 74 65 | 7d 0d 0d 49 66 20 79 6f |Appetite|}..If yo|
|000005d0| 75 20 65 76 65 72 20 77 | 72 6f 74 65 20 61 20 6c |u ever w|rote a l|
|000005e0| 61 72 67 65 20 73 68 65 | 6c 6c 20 73 63 72 69 70 |arge she|ll scrip|
|000005f0| 74 2c 20 79 6f 75 20 70 | 72 6f 62 61 62 6c 79 20 |t, you p|robably |
|00000600| 6b 6e 6f 77 20 74 68 69 | 73 0d 66 65 65 6c 69 6e |know thi|s.feelin|
|00000610| 67 3a 20 79 6f 75 27 64 | 20 6c 6f 76 65 20 74 6f |g: you'd| love to|
|00000620| 20 61 64 64 20 79 65 74 | 20 61 6e 6f 74 68 65 72 | add yet| another|
|00000630| 20 66 65 61 74 75 72 65 | 2c 20 62 75 74 20 69 74 | feature|, but it|
|00000640| 27 73 20 61 6c 72 65 61 | 64 79 20 73 6f 0d 73 6c |'s alrea|dy so.sl|
|00000650| 6f 77 2c 20 61 6e 64 20 | 73 6f 20 62 69 67 2c 20 |ow, and |so big, |
|00000660| 61 6e 64 20 73 6f 20 63 | 6f 6d 70 6c 69 63 61 74 |and so c|omplicat|
|00000670| 65 64 3b 20 6f 72 20 74 | 68 65 20 66 65 61 74 75 |ed; or t|he featu|
|00000680| 72 65 20 69 6e 76 6f 6c | 76 65 73 20 61 20 73 79 |re invol|ves a sy|
|00000690| 73 74 65 6d 0d 63 61 6c | 6c 20 6f 72 20 6f 74 68 |stem.cal|l or oth|
|000006a0| 65 72 20 66 75 6e 63 74 | 69 6f 6e 20 74 68 61 74 |er funct|ion that|
|000006b0| 20 69 73 20 6f 6e 6c 79 | 20 61 63 63 65 73 73 69 | is only| accessi|
|000006c0| 62 6c 65 20 66 72 6f 6d | 20 43 20 5c 6c 64 6f 74 |ble from| C \ldot|
|000006d0| 73 20 20 55 73 75 61 6c | 6c 79 0d 74 68 65 20 70 |s Usual|ly.the p|
|000006e0| 72 6f 62 6c 65 6d 20 61 | 74 20 68 61 6e 64 20 69 |roblem a|t hand i|
|000006f0| 73 6e 27 74 20 73 65 72 | 69 6f 75 73 20 65 6e 6f |sn't ser|ious eno|
|00000700| 75 67 68 20 74 6f 20 77 | 61 72 72 61 6e 74 20 72 |ugh to w|arrant r|
|00000710| 65 77 72 69 74 69 6e 67 | 20 74 68 65 0d 73 63 72 |ewriting| the.scr|
|00000720| 69 70 74 20 69 6e 20 43 | 3b 20 70 65 72 68 61 70 |ipt in C|; perhap|
|00000730| 73 20 62 65 63 61 75 73 | 65 20 74 68 65 20 70 72 |s becaus|e the pr|
|00000740| 6f 62 6c 65 6d 20 72 65 | 71 75 69 72 65 73 20 76 |oblem re|quires v|
|00000750| 61 72 69 61 62 6c 65 2d | 6c 65 6e 67 74 68 0d 73 |ariable-|length.s|
|00000760| 74 72 69 6e 67 73 20 6f | 72 20 6f 74 68 65 72 20 |trings o|r other |
|00000770| 64 61 74 61 20 74 79 70 | 65 73 20 28 6c 69 6b 65 |data typ|es (like|
|00000780| 20 73 6f 72 74 65 64 20 | 6c 69 73 74 73 20 6f 66 | sorted |lists of|
|00000790| 20 66 69 6c 65 20 6e 61 | 6d 65 73 29 20 74 68 61 | file na|mes) tha|
|000007a0| 74 20 61 72 65 0d 65 61 | 73 79 20 69 6e 20 74 68 |t are.ea|sy in th|
|000007b0| 65 20 73 68 65 6c 6c 20 | 62 75 74 20 6c 6f 74 73 |e shell |but lots|
|000007c0| 20 6f 66 20 77 6f 72 6b | 20 74 6f 20 69 6d 70 6c | of work| to impl|
|000007d0| 65 6d 65 6e 74 20 69 6e | 20 43 3b 20 6f 72 20 70 |ement in| C; or p|
|000007e0| 65 72 68 61 70 73 20 6a | 75 73 74 0d 62 65 63 61 |erhaps j|ust.beca|
|000007f0| 75 73 65 20 79 6f 75 27 | 72 65 20 6e 6f 74 20 73 |use you'|re not s|
|00000800| 75 66 66 69 63 69 65 6e | 74 6c 79 20 66 61 6d 69 |ufficien|tly fami|
|00000810| 6c 69 61 72 20 77 69 74 | 68 20 43 2e 0d 0d 49 6e |liar wit|h C...In|
|00000820| 20 73 75 63 68 20 63 61 | 73 65 73 2c 20 50 79 74 | such ca|ses, Pyt|
|00000830| 68 6f 6e 20 6d 61 79 20 | 62 65 20 6a 75 73 74 20 |hon may |be just |
|00000840| 74 68 65 20 6c 61 6e 67 | 75 61 67 65 20 66 6f 72 |the lang|uage for|
|00000850| 20 79 6f 75 2e 20 20 50 | 79 74 68 6f 6e 20 69 73 | you. P|ython is|
|00000860| 0d 73 69 6d 70 6c 65 20 | 74 6f 20 75 73 65 2c 20 |.simple |to use, |
|00000870| 62 75 74 20 69 74 20 69 | 73 20 61 20 72 65 61 6c |but it i|s a real|
|00000880| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 6c 61 6e | program|ming lan|
|00000890| 67 75 61 67 65 2c 20 6f | 66 66 65 72 69 6e 67 20 |guage, o|ffering |
|000008a0| 6d 75 63 68 0d 6d 6f 72 | 65 20 73 74 72 75 63 74 |much.mor|e struct|
|000008b0| 75 72 65 20 61 6e 64 20 | 73 75 70 70 6f 72 74 20 |ure and |support |
|000008c0| 66 6f 72 20 6c 61 72 67 | 65 20 70 72 6f 67 72 61 |for larg|e progra|
|000008d0| 6d 73 20 74 68 61 6e 20 | 74 68 65 20 73 68 65 6c |ms than |the shel|
|000008e0| 6c 20 68 61 73 2e 20 20 | 4f 6e 0d 74 68 65 20 6f |l has. |On.the o|
|000008f0| 74 68 65 72 20 68 61 6e | 64 2c 20 69 74 20 61 6c |ther han|d, it al|
|00000900| 73 6f 20 6f 66 66 65 72 | 73 20 6d 75 63 68 20 6d |so offer|s much m|
|00000910| 6f 72 65 20 65 72 72 6f | 72 20 63 68 65 63 6b 69 |ore erro|r checki|
|00000920| 6e 67 20 74 68 61 6e 20 | 43 2c 20 61 6e 64 2c 0d |ng than |C, and,.|
|00000930| 62 65 69 6e 67 20 61 20 | 7b 5c 65 6d 20 76 65 72 |being a |{\em ver|
|00000940| 79 2d 68 69 67 68 2d 6c | 65 76 65 6c 20 6c 61 6e |y-high-l|evel lan|
|00000950| 67 75 61 67 65 7d 2c 20 | 69 74 20 68 61 73 20 68 |guage}, |it has h|
|00000960| 69 67 68 2d 6c 65 76 65 | 6c 20 64 61 74 61 20 74 |igh-leve|l data t|
|00000970| 79 70 65 73 0d 62 75 69 | 6c 74 20 69 6e 2c 20 73 |ypes.bui|lt in, s|
|00000980| 75 63 68 20 61 73 20 66 | 6c 65 78 69 62 6c 65 20 |uch as f|lexible |
|00000990| 61 72 72 61 79 73 20 61 | 6e 64 20 64 69 63 74 69 |arrays a|nd dicti|
|000009a0| 6f 6e 61 72 69 65 73 20 | 74 68 61 74 20 77 6f 75 |onaries |that wou|
|000009b0| 6c 64 20 63 6f 73 74 20 | 79 6f 75 0d 64 61 79 73 |ld cost |you.days|
|000009c0| 20 74 6f 20 69 6d 70 6c | 65 6d 65 6e 74 20 65 66 | to impl|ement ef|
|000009d0| 66 69 63 69 65 6e 74 6c | 79 20 69 6e 20 43 2e 20 |ficientl|y in C. |
|000009e0| 20 42 65 63 61 75 73 65 | 20 6f 66 20 69 74 73 20 | Because| of its |
|000009f0| 6d 6f 72 65 20 67 65 6e | 65 72 61 6c 20 64 61 74 |more gen|eral dat|
|00000a00| 61 0d 74 79 70 65 73 20 | 50 79 74 68 6f 6e 20 69 |a.types |Python i|
|00000a10| 73 20 61 70 70 6c 69 63 | 61 62 6c 65 20 74 6f 20 |s applic|able to |
|00000a20| 61 20 6d 75 63 68 20 6c | 61 72 67 65 72 20 70 72 |a much l|arger pr|
|00000a30| 6f 62 6c 65 6d 20 64 6f | 6d 61 69 6e 20 74 68 61 |oblem do|main tha|
|00000a40| 6e 20 7b 5c 65 6d 0d 41 | 77 6b 7d 20 6f 72 20 65 |n {\em.A|wk} or e|
|00000a50| 76 65 6e 20 7b 5c 65 6d | 20 50 65 72 6c 7d 2c 20 |ven {\em| Perl}, |
|00000a60| 79 65 74 20 6d 61 6e 79 | 20 74 68 69 6e 67 73 20 |yet many| things |
|00000a70| 61 72 65 20 61 74 20 6c | 65 61 73 74 20 61 73 20 |are at l|east as |
|00000a80| 65 61 73 79 20 69 6e 0d | 50 79 74 68 6f 6e 20 61 |easy in.|Python a|
|00000a90| 73 20 69 6e 20 74 68 6f | 73 65 20 6c 61 6e 67 75 |s in tho|se langu|
|00000aa0| 61 67 65 73 2e 0d 0d 50 | 79 74 68 6f 6e 20 61 6c |ages...P|ython al|
|00000ab0| 6c 6f 77 73 20 79 6f 75 | 20 74 6f 20 73 70 6c 69 |lows you| to spli|
|00000ac0| 74 20 75 70 20 79 6f 75 | 72 20 70 72 6f 67 72 61 |t up you|r progra|
|00000ad0| 6d 20 69 6e 20 6d 6f 64 | 75 6c 65 73 20 74 68 61 |m in mod|ules tha|
|00000ae0| 74 20 63 61 6e 20 62 65 | 0d 72 65 75 73 65 64 20 |t can be|.reused |
|00000af0| 69 6e 20 6f 74 68 65 72 | 20 50 79 74 68 6f 6e 20 |in other| Python |
|00000b00| 70 72 6f 67 72 61 6d 73 | 2e 20 20 49 74 20 63 6f |programs|. It co|
|00000b10| 6d 65 73 20 77 69 74 68 | 20 61 20 6c 61 72 67 65 |mes with| a large|
|00000b20| 20 63 6f 6c 6c 65 63 74 | 69 6f 6e 20 6f 66 0d 73 | collect|ion of.s|
|00000b30| 74 61 6e 64 61 72 64 20 | 6d 6f 64 75 6c 65 73 20 |tandard |modules |
|00000b40| 74 68 61 74 20 79 6f 75 | 20 63 61 6e 20 75 73 65 |that you| can use|
|00000b50| 20 61 73 20 74 68 65 20 | 62 61 73 69 73 20 6f 66 | as the |basis of|
|00000b60| 20 79 6f 75 72 20 70 72 | 6f 67 72 61 6d 73 20 2d | your pr|ograms -|
|00000b70| 2d 2d 20 6f 72 0d 61 73 | 20 65 78 61 6d 70 6c 65 |-- or.as| example|
|00000b80| 73 20 74 6f 20 73 74 61 | 72 74 20 6c 65 61 72 6e |s to sta|rt learn|
|00000b90| 69 6e 67 20 74 6f 20 70 | 72 6f 67 72 61 6d 20 69 |ing to p|rogram i|
|00000ba0| 6e 20 50 79 74 68 6f 6e | 2e 20 20 54 68 65 72 65 |n Python|. There|
|00000bb0| 20 61 72 65 20 61 6c 73 | 6f 0d 62 75 69 6c 74 2d | are als|o.built-|
|00000bc0| 69 6e 20 6d 6f 64 75 6c | 65 73 20 74 68 61 74 20 |in modul|es that |
|00000bd0| 70 72 6f 76 69 64 65 20 | 74 68 69 6e 67 73 20 6c |provide |things l|
|00000be0| 69 6b 65 20 66 69 6c 65 | 20 49 2f 4f 2c 20 73 79 |ike file| I/O, sy|
|00000bf0| 73 74 65 6d 20 63 61 6c | 6c 73 2c 0d 73 6f 63 6b |stem cal|ls,.sock|
|00000c00| 65 74 73 2c 20 61 6e 64 | 20 65 76 65 6e 20 61 20 |ets, and| even a |
|00000c10| 67 65 6e 65 72 69 63 20 | 69 6e 74 65 72 66 61 63 |generic |interfac|
|00000c20| 65 20 74 6f 20 77 69 6e | 64 6f 77 20 73 79 73 74 |e to win|dow syst|
|00000c30| 65 6d 73 20 28 53 54 44 | 57 49 4e 29 2e 0d 0d 50 |ems (STD|WIN)...P|
|00000c40| 79 74 68 6f 6e 20 69 73 | 20 61 6e 20 69 6e 74 65 |ython is| an inte|
|00000c50| 72 70 72 65 74 65 64 20 | 6c 61 6e 67 75 61 67 65 |rpreted |language|
|00000c60| 2c 20 77 68 69 63 68 20 | 63 61 6e 20 73 61 76 65 |, which |can save|
|00000c70| 20 79 6f 75 20 63 6f 6e | 73 69 64 65 72 61 62 6c | you con|siderabl|
|00000c80| 65 20 74 69 6d 65 0d 64 | 75 72 69 6e 67 20 70 72 |e time.d|uring pr|
|00000c90| 6f 67 72 61 6d 20 64 65 | 76 65 6c 6f 70 6d 65 6e |ogram de|velopmen|
|00000ca0| 74 20 62 65 63 61 75 73 | 65 20 6e 6f 20 63 6f 6d |t becaus|e no com|
|00000cb0| 70 69 6c 61 74 69 6f 6e | 20 61 6e 64 20 6c 69 6e |pilation| and lin|
|00000cc0| 6b 69 6e 67 20 69 73 0d | 6e 65 63 65 73 73 61 72 |king is.|necessar|
|00000cd0| 79 2e 20 20 54 68 65 20 | 69 6e 74 65 72 70 72 65 |y. The |interpre|
|00000ce0| 74 65 72 20 63 61 6e 20 | 62 65 20 75 73 65 64 20 |ter can |be used |
|00000cf0| 69 6e 74 65 72 61 63 74 | 69 76 65 6c 79 2c 20 77 |interact|ively, w|
|00000d00| 68 69 63 68 20 6d 61 6b | 65 73 20 69 74 0d 65 61 |hich mak|es it.ea|
|00000d10| 73 79 20 74 6f 20 65 78 | 70 65 72 69 6d 65 6e 74 |sy to ex|periment|
|00000d20| 20 77 69 74 68 20 66 65 | 61 74 75 72 65 73 20 6f | with fe|atures o|
|00000d30| 66 20 74 68 65 20 6c 61 | 6e 67 75 61 67 65 2c 20 |f the la|nguage, |
|00000d40| 74 6f 20 77 72 69 74 65 | 20 74 68 72 6f 77 2d 61 |to write| throw-a|
|00000d50| 77 61 79 0d 70 72 6f 67 | 72 61 6d 73 2c 20 6f 72 |way.prog|rams, or|
|00000d60| 20 74 6f 20 74 65 73 74 | 20 66 75 6e 63 74 69 6f | to test| functio|
|00000d70| 6e 73 20 64 75 72 69 6e | 67 20 62 6f 74 74 6f 6d |ns durin|g bottom|
|00000d80| 2d 75 70 20 70 72 6f 67 | 72 61 6d 20 64 65 76 65 |-up prog|ram deve|
|00000d90| 6c 6f 70 6d 65 6e 74 2e | 0d 49 74 20 69 73 20 61 |lopment.|.It is a|
|00000da0| 6c 73 6f 20 61 20 68 61 | 6e 64 79 20 64 65 73 6b |lso a ha|ndy desk|
|00000db0| 20 63 61 6c 63 75 6c 61 | 74 6f 72 2e 0d 0d 50 79 | calcula|tor...Py|
|00000dc0| 74 68 6f 6e 20 61 6c 6c | 6f 77 73 20 77 72 69 74 |thon all|ows writ|
|00000dd0| 69 6e 67 20 76 65 72 79 | 20 63 6f 6d 70 61 63 74 |ing very| compact|
|00000de0| 20 61 6e 64 20 72 65 61 | 64 61 62 6c 65 20 70 72 | and rea|dable pr|
|00000df0| 6f 67 72 61 6d 73 2e 20 | 20 50 72 6f 67 72 61 6d |ograms. | Program|
|00000e00| 73 0d 77 72 69 74 74 65 | 6e 20 69 6e 20 50 79 74 |s.writte|n in Pyt|
|00000e10| 68 6f 6e 20 61 72 65 20 | 74 79 70 69 63 61 6c 6c |hon are |typicall|
|00000e20| 79 20 6d 75 63 68 20 73 | 68 6f 72 74 65 72 20 74 |y much s|horter t|
|00000e30| 68 61 6e 20 65 71 75 69 | 76 61 6c 65 6e 74 20 43 |han equi|valent C|
|00000e40| 0d 70 72 6f 67 72 61 6d | 73 2c 20 66 6f 72 20 73 |.program|s, for s|
|00000e50| 65 76 65 72 61 6c 20 72 | 65 61 73 6f 6e 73 3a 0d |everal r|easons:.|
|00000e60| 5c 62 65 67 69 6e 7b 69 | 74 65 6d 69 7a 65 7d 0d |\begin{i|temize}.|
|00000e70| 5c 69 74 65 6d 0d 74 68 | 65 20 68 69 67 68 2d 6c |\item.th|e high-l|
|00000e80| 65 76 65 6c 20 64 61 74 | 61 20 74 79 70 65 73 20 |evel dat|a types |
|00000e90| 61 6c 6c 6f 77 20 79 6f | 75 20 74 6f 20 65 78 70 |allow yo|u to exp|
|00000ea0| 72 65 73 73 20 63 6f 6d | 70 6c 65 78 20 6f 70 65 |ress com|plex ope|
|00000eb0| 72 61 74 69 6f 6e 73 20 | 69 6e 20 61 0d 73 69 6e |rations |in a.sin|
|00000ec0| 67 6c 65 20 73 74 61 74 | 65 6d 65 6e 74 3b 0d 5c |gle stat|ement;.\|
|00000ed0| 69 74 65 6d 0d 73 74 61 | 74 65 6d 65 6e 74 20 67 |item.sta|tement g|
|00000ee0| 72 6f 75 70 69 6e 67 20 | 69 73 20 64 6f 6e 65 20 |rouping |is done |
|00000ef0| 62 79 20 69 6e 64 65 6e | 74 61 74 69 6f 6e 20 69 |by inden|tation i|
|00000f00| 6e 73 74 65 61 64 20 6f | 66 20 62 65 67 69 6e 2f |nstead o|f begin/|
|00000f10| 65 6e 64 0d 62 72 61 63 | 6b 65 74 73 3b 0d 5c 69 |end.brac|kets;.\i|
|00000f20| 74 65 6d 0d 6e 6f 20 76 | 61 72 69 61 62 6c 65 20 |tem.no v|ariable |
|00000f30| 6f 72 20 61 72 67 75 6d | 65 6e 74 20 64 65 63 6c |or argum|ent decl|
|00000f40| 61 72 61 74 69 6f 6e 73 | 20 61 72 65 20 6e 65 63 |arations| are nec|
|00000f50| 65 73 73 61 72 79 2e 0d | 5c 65 6e 64 7b 69 74 65 |essary..|\end{ite|
|00000f60| 6d 69 7a 65 7d 0d 0d 50 | 79 74 68 6f 6e 20 69 73 |mize}..P|ython is|
|00000f70| 20 7b 5c 65 6d 20 65 78 | 74 65 6e 73 69 62 6c 65 | {\em ex|tensible|
|00000f80| 7d 3a 20 69 66 20 79 6f | 75 20 6b 6e 6f 77 20 68 |}: if yo|u know h|
|00000f90| 6f 77 20 74 6f 20 70 72 | 6f 67 72 61 6d 20 69 6e |ow to pr|ogram in|
|00000fa0| 20 43 20 69 74 20 69 73 | 20 65 61 73 79 0d 74 6f | C it is| easy.to|
|00000fb0| 20 61 64 64 20 61 20 6e | 65 77 20 62 75 69 6c 74 | add a n|ew built|
|00000fc0| 2d 69 6e 0d 66 75 6e 63 | 74 69 6f 6e 20 6f 72 0d |-in.func|tion or.|
|00000fd0| 6d 6f 64 75 6c 65 20 74 | 6f 20 74 68 65 20 69 6e |module t|o the in|
|00000fe0| 74 65 72 70 72 65 74 65 | 72 2c 20 65 69 74 68 65 |terprete|r, eithe|
|00000ff0| 72 20 74 6f 0d 70 65 72 | 66 6f 72 6d 20 63 72 69 |r to.per|form cri|
|00001000| 74 69 63 61 6c 20 6f 70 | 65 72 61 74 69 6f 6e 73 |tical op|erations|
|00001010| 20 61 74 20 6d 61 78 69 | 6d 75 6d 20 73 70 65 65 | at maxi|mum spee|
|00001020| 64 2c 20 6f 72 20 74 6f | 20 6c 69 6e 6b 20 50 79 |d, or to| link Py|
|00001030| 74 68 6f 6e 0d 70 72 6f | 67 72 61 6d 73 20 74 6f |thon.pro|grams to|
|00001040| 20 6c 69 62 72 61 72 69 | 65 73 20 74 68 61 74 20 | librari|es that |
|00001050| 6d 61 79 20 6f 6e 6c 79 | 20 62 65 20 61 76 61 69 |may only| be avai|
|00001060| 6c 61 62 6c 65 20 69 6e | 20 62 69 6e 61 72 79 20 |lable in| binary |
|00001070| 66 6f 72 6d 20 28 73 75 | 63 68 0d 61 73 20 61 20 |form (su|ch.as a |
|00001080| 76 65 6e 64 6f 72 2d 73 | 70 65 63 69 66 69 63 20 |vendor-s|pecific |
|00001090| 67 72 61 70 68 69 63 73 | 20 6c 69 62 72 61 72 79 |graphics| library|
|000010a0| 29 2e 20 20 4f 6e 63 65 | 20 79 6f 75 20 61 72 65 |). Once| you are|
|000010b0| 20 72 65 61 6c 6c 79 20 | 68 6f 6f 6b 65 64 2c 0d | really |hooked,.|
|000010c0| 79 6f 75 20 63 61 6e 20 | 6c 69 6e 6b 20 74 68 65 |you can |link the|
|000010d0| 20 50 79 74 68 6f 6e 20 | 69 6e 74 65 72 70 72 65 | Python |interpre|
|000010e0| 74 65 72 20 69 6e 74 6f | 20 61 6e 20 61 70 70 6c |ter into| an appl|
|000010f0| 69 63 61 74 69 6f 6e 20 | 77 72 69 74 74 65 6e 20 |ication |written |
|00001100| 69 6e 20 43 0d 61 6e 64 | 20 75 73 65 20 69 74 20 |in C.and| use it |
|00001110| 61 73 20 61 6e 20 65 78 | 74 65 6e 73 69 6f 6e 20 |as an ex|tension |
|00001120| 6f 72 20 63 6f 6d 6d 61 | 6e 64 20 6c 61 6e 67 75 |or comma|nd langu|
|00001130| 61 67 65 20 66 6f 72 20 | 74 68 61 74 20 61 70 70 |age for |that app|
|00001140| 6c 69 63 61 74 69 6f 6e | 2e 0d 0d 42 79 20 74 68 |lication|...By th|
|00001150| 65 20 77 61 79 2c 20 74 | 68 65 20 6c 61 6e 67 75 |e way, t|he langu|
|00001160| 61 67 65 20 69 73 20 6e | 61 6d 65 64 20 61 66 74 |age is n|amed aft|
|00001170| 65 72 20 74 68 65 20 42 | 42 43 20 73 68 6f 77 20 |er the B|BC show |
|00001180| 60 60 4d 6f 6e 74 79 0d | 50 79 74 68 6f 6e 27 73 |``Monty.|Python's|
|00001190| 20 46 6c 79 69 6e 67 20 | 43 69 72 63 75 73 27 27 | Flying |Circus''|
|000011a0| 20 61 6e 64 20 68 61 73 | 20 6e 6f 74 68 69 6e 67 | and has| nothing|
|000011b0| 20 74 6f 20 64 6f 20 77 | 69 74 68 20 6e 61 73 74 | to do w|ith nast|
|000011c0| 79 20 72 65 70 74 69 6c | 65 73 2e 2e 2e 0d 0d 5c |y reptil|es.....\|
|000011d0| 73 65 63 74 69 6f 6e 7b | 57 68 65 72 65 20 46 72 |section{|Where Fr|
|000011e0| 6f 6d 20 48 65 72 65 7d | 0d 0d 4e 6f 77 20 74 68 |om Here}|..Now th|
|000011f0| 61 74 20 79 6f 75 20 61 | 72 65 20 61 6c 6c 20 65 |at you a|re all e|
|00001200| 78 63 69 74 65 64 20 61 | 62 6f 75 74 20 50 79 74 |xcited a|bout Pyt|
|00001210| 68 6f 6e 2c 20 79 6f 75 | 27 6c 6c 20 77 61 6e 74 |hon, you|'ll want|
|00001220| 20 74 6f 20 65 78 61 6d | 69 6e 65 20 69 74 0d 69 | to exam|ine it.i|
|00001230| 6e 20 73 6f 6d 65 20 6d | 6f 72 65 20 64 65 74 61 |n some m|ore deta|
|00001240| 69 6c 2e 20 20 53 69 6e | 63 65 20 74 68 65 20 62 |il. Sin|ce the b|
|00001250| 65 73 74 20 77 61 79 20 | 74 6f 20 6c 65 61 72 6e |est way |to learn|
|00001260| 20 61 20 6c 61 6e 67 75 | 61 67 65 20 69 73 0d 75 | a langu|age is.u|
|00001270| 73 69 6e 67 20 69 74 2c | 20 79 6f 75 20 61 72 65 |sing it,| you are|
|00001280| 20 69 6e 76 69 74 65 64 | 20 68 65 72 65 20 74 6f | invited| here to|
|00001290| 20 64 6f 20 73 6f 2e 0d | 0d 49 6e 20 74 68 65 20 | do so..|.In the |
|000012a0| 6e 65 78 74 20 63 68 61 | 70 74 65 72 2c 20 74 68 |next cha|pter, th|
|000012b0| 65 20 6d 65 63 68 61 6e | 69 63 73 20 6f 66 20 75 |e mechan|ics of u|
|000012c0| 73 69 6e 67 20 74 68 65 | 20 69 6e 74 65 72 70 72 |sing the| interpr|
|000012d0| 65 74 65 72 20 61 72 65 | 0d 65 78 70 6c 61 69 6e |eter are|.explain|
|000012e0| 65 64 2e 20 20 54 68 69 | 73 20 69 73 20 72 61 74 |ed. Thi|s is rat|
|000012f0| 68 65 72 20 6d 75 6e 64 | 61 6e 65 20 69 6e 66 6f |her mund|ane info|
|00001300| 72 6d 61 74 69 6f 6e 2c | 20 62 75 74 20 65 73 73 |rmation,| but ess|
|00001310| 65 6e 74 69 61 6c 20 66 | 6f 72 0d 74 72 79 69 6e |ential f|or.tryin|
|00001320| 67 20 6f 75 74 20 74 68 | 65 20 65 78 61 6d 70 6c |g out th|e exampl|
|00001330| 65 73 20 73 68 6f 77 6e | 20 6c 61 74 65 72 2e 0d |es shown| later..|
|00001340| 0d 54 68 65 20 72 65 73 | 74 20 6f 66 20 74 68 65 |.The res|t of the|
|00001350| 20 74 75 74 6f 72 69 61 | 6c 20 69 6e 74 72 6f 64 | tutoria|l introd|
|00001360| 75 63 65 73 20 76 61 72 | 69 6f 75 73 20 66 65 61 |uces var|ious fea|
|00001370| 74 75 72 65 73 20 6f 66 | 20 74 68 65 20 50 79 74 |tures of| the Pyt|
|00001380| 68 6f 6e 0d 6c 61 6e 67 | 75 61 67 65 20 61 6e 64 |hon.lang|uage and|
|00001390| 20 73 79 73 74 65 6d 20 | 74 68 6f 75 67 68 20 65 | system |though e|
|000013a0| 78 61 6d 70 6c 65 73 2c | 20 62 65 67 69 6e 6e 69 |xamples,| beginni|
|000013b0| 6e 67 20 77 69 74 68 20 | 73 69 6d 70 6c 65 0d 65 |ng with |simple.e|
|000013c0| 78 70 72 65 73 73 69 6f | 6e 73 2c 20 73 74 61 74 |xpressio|ns, stat|
|000013d0| 65 6d 65 6e 74 73 20 61 | 6e 64 20 64 61 74 61 20 |ements a|nd data |
|000013e0| 74 79 70 65 73 2c 20 74 | 68 72 6f 75 67 68 20 66 |types, t|hrough f|
|000013f0| 75 6e 63 74 69 6f 6e 73 | 20 61 6e 64 20 6d 6f 64 |unctions| and mod|
|00001400| 75 6c 65 73 2c 0d 61 6e | 64 20 66 69 6e 61 6c 6c |ules,.an|d finall|
|00001410| 79 20 74 6f 75 63 68 69 | 6e 67 20 75 70 6f 6e 20 |y touchi|ng upon |
|00001420| 61 64 76 61 6e 63 65 64 | 20 63 6f 6e 63 65 70 74 |advanced| concept|
|00001430| 73 20 6c 69 6b 65 20 65 | 78 63 65 70 74 69 6f 6e |s like e|xception|
|00001440| 73 0d 61 6e 64 20 75 73 | 65 72 2d 64 65 66 69 6e |s.and us|er-defin|
|00001450| 65 64 20 63 6c 61 73 73 | 65 73 2e 0d 0d 57 68 65 |ed class|es...Whe|
|00001460| 6e 20 79 6f 75 27 72 65 | 20 74 68 72 6f 75 67 68 |n you're| through|
|00001470| 20 77 69 74 68 20 74 68 | 65 20 74 75 74 6f 72 69 | with th|e tutori|
|00001480| 61 6c 20 28 6f 72 20 6a | 75 73 74 20 67 65 74 74 |al (or j|ust gett|
|00001490| 69 6e 67 20 62 6f 72 65 | 64 29 2c 20 79 6f 75 0d |ing bore|d), you.|
|000014a0| 73 68 6f 75 6c 64 20 72 | 65 61 64 20 74 68 65 20 |should r|ead the |
|000014b0| 4c 69 62 72 61 72 79 20 | 52 65 66 65 72 65 6e 63 |Library |Referenc|
|000014c0| 65 2c 20 77 68 69 63 68 | 20 67 69 76 65 73 20 63 |e, which| gives c|
|000014d0| 6f 6d 70 6c 65 74 65 20 | 28 74 68 6f 75 67 68 20 |omplete |(though |
|000014e0| 74 65 72 73 65 29 0d 72 | 65 66 65 72 65 6e 63 65 |terse).r|eference|
|000014f0| 20 6d 61 74 65 72 69 61 | 6c 20 61 62 6f 75 74 20 | materia|l about |
|00001500| 62 75 69 6c 74 2d 69 6e | 20 61 6e 64 20 73 74 61 |built-in| and sta|
|00001510| 6e 64 61 72 64 20 74 79 | 70 65 73 2c 20 66 75 6e |ndard ty|pes, fun|
|00001520| 63 74 69 6f 6e 73 20 61 | 6e 64 0d 6d 6f 64 75 6c |ctions a|nd.modul|
|00001530| 65 73 20 74 68 61 74 20 | 63 61 6e 20 73 61 76 65 |es that |can save|
|00001540| 20 79 6f 75 20 61 20 6c | 6f 74 20 6f 66 20 74 69 | you a l|ot of ti|
|00001550| 6d 65 20 77 68 65 6e 20 | 77 72 69 74 69 6e 67 20 |me when |writing |
|00001560| 50 79 74 68 6f 6e 20 70 | 72 6f 67 72 61 6d 73 2e |Python p|rograms.|
|00001570| 0d 0d 0d 5c 63 68 61 70 | 74 65 72 7b 55 73 69 6e |...\chap|ter{Usin|
|00001580| 67 20 74 68 65 20 50 79 | 74 68 6f 6e 20 49 6e 74 |g the Py|thon Int|
|00001590| 65 72 70 72 65 74 65 72 | 7d 0d 0d 5c 73 65 63 74 |erpreter|}..\sect|
|000015a0| 69 6f 6e 7b 49 6e 76 6f | 6b 69 6e 67 20 74 68 65 |ion{Invo|king the|
|000015b0| 20 49 6e 74 65 72 70 72 | 65 74 65 72 7d 0d 0d 54 | Interpr|eter}..T|
|000015c0| 68 65 20 50 79 74 68 6f | 6e 20 69 6e 74 65 72 70 |he Pytho|n interp|
|000015d0| 72 65 74 65 72 20 69 73 | 20 75 73 75 61 6c 6c 79 |reter is| usually|
|000015e0| 20 69 6e 73 74 61 6c 6c | 65 64 20 61 73 20 7b 5c | install|ed as {\|
|000015f0| 74 74 20 2f 75 73 72 2f | 6c 6f 63 61 6c 2f 62 69 |tt /usr/|local/bi|
|00001600| 6e 2f 70 79 74 68 6f 6e | 7d 0d 6f 6e 20 74 68 6f |n/python|}.on tho|
|00001610| 73 65 20 6d 61 63 68 69 | 6e 65 73 20 77 68 65 72 |se machi|nes wher|
|00001620| 65 20 69 74 20 69 73 20 | 61 76 61 69 6c 61 62 6c |e it is |availabl|
|00001630| 65 3b 20 70 75 74 74 69 | 6e 67 20 7b 5c 74 74 20 |e; putti|ng {\tt |
|00001640| 2f 75 73 72 2f 6c 6f 63 | 61 6c 2f 62 69 6e 7d 20 |/usr/loc|al/bin} |
|00001650| 69 6e 0d 79 6f 75 72 20 | 7b 5c 55 4e 49 58 7d 20 |in.your |{\UNIX} |
|00001660| 73 68 65 6c 6c 27 73 20 | 73 65 61 72 63 68 20 70 |shell's |search p|
|00001670| 61 74 68 20 6d 61 6b 65 | 73 20 69 74 20 70 6f 73 |ath make|s it pos|
|00001680| 73 69 62 6c 65 20 74 6f | 20 73 74 61 72 74 20 69 |sible to| start i|
|00001690| 74 20 62 79 0d 74 79 70 | 69 6e 67 20 74 68 65 20 |t by.typ|ing the |
|000016a0| 63 6f 6d 6d 61 6e 64 0d | 0d 5c 62 63 6f 64 65 5c |command.|.\bcode\|
|000016b0| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0d |begin{ve|rbatim}.|
|000016c0| 70 79 74 68 6f 6e 0d 5c | 65 6e 64 7b 76 65 72 62 |python.\|end{verb|
|000016d0| 61 74 69 6d 7d 5c 65 63 | 6f 64 65 0d 25 0d 74 6f |atim}\ec|ode.%.to|
|000016e0| 20 74 68 65 20 73 68 65 | 6c 6c 2e 20 20 53 69 6e | the she|ll. Sin|
|000016f0| 63 65 20 74 68 65 20 63 | 68 6f 69 63 65 20 6f 66 |ce the c|hoice of|
|00001700| 20 74 68 65 20 64 69 72 | 65 63 74 6f 72 79 20 77 | the dir|ectory w|
|00001710| 68 65 72 65 20 74 68 65 | 20 69 6e 74 65 72 70 72 |here the| interpr|
|00001720| 65 74 65 72 0d 6c 69 76 | 65 73 20 69 73 20 61 6e |eter.liv|es is an|
|00001730| 20 69 6e 73 74 61 6c 6c | 61 74 69 6f 6e 20 6f 70 | install|ation op|
|00001740| 74 69 6f 6e 2c 20 6f 74 | 68 65 72 20 70 6c 61 63 |tion, ot|her plac|
|00001750| 65 73 20 61 72 65 20 70 | 6f 73 73 69 62 6c 65 3b |es are p|ossible;|
|00001760| 20 63 68 65 63 6b 20 77 | 69 74 68 0d 79 6f 75 72 | check w|ith.your|
|00001770| 20 6c 6f 63 61 6c 20 50 | 79 74 68 6f 6e 20 67 75 | local P|ython gu|
|00001780| 72 75 20 6f 72 20 73 79 | 73 74 65 6d 20 61 64 6d |ru or sy|stem adm|
|00001790| 69 6e 69 73 74 72 61 74 | 6f 72 2e 20 20 28 45 2e |inistrat|or. (E.|
|000017a0| 67 2e 2c 20 7b 5c 74 74 | 0d 2f 75 73 72 2f 6c 6f |g., {\tt|./usr/lo|
|000017b0| 63 61 6c 2f 70 79 74 68 | 6f 6e 7d 20 69 73 20 61 |cal/pyth|on} is a|
|000017c0| 20 70 6f 70 75 6c 61 72 | 20 61 6c 74 65 72 6e 61 | popular| alterna|
|000017d0| 74 69 76 65 20 6c 6f 63 | 61 74 69 6f 6e 2e 29 0d |tive loc|ation.).|
|000017e0| 0d 54 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 |.The int|erpreter|
|000017f0| 20 6f 70 65 72 61 74 65 | 73 20 73 6f 6d 65 77 68 | operate|s somewh|
|00001800| 61 74 20 6c 69 6b 65 20 | 74 68 65 20 7b 5c 55 4e |at like |the {\UN|
|00001810| 49 58 7d 20 73 68 65 6c | 6c 3a 20 77 68 65 6e 20 |IX} shel|l: when |
|00001820| 63 61 6c 6c 65 64 0d 77 | 69 74 68 20 73 74 61 6e |called.w|ith stan|
|00001830| 64 61 72 64 20 69 6e 70 | 75 74 20 63 6f 6e 6e 65 |dard inp|ut conne|
|00001840| 63 74 65 64 20 74 6f 20 | 61 20 74 74 79 20 64 65 |cted to |a tty de|
|00001850| 76 69 63 65 2c 20 69 74 | 20 72 65 61 64 73 20 61 |vice, it| reads a|
|00001860| 6e 64 20 65 78 65 63 75 | 74 65 73 0d 63 6f 6d 6d |nd execu|tes.comm|
|00001870| 61 6e 64 73 20 69 6e 74 | 65 72 61 63 74 69 76 65 |ands int|eractive|
|00001880| 6c 79 3b 20 77 68 65 6e | 20 63 61 6c 6c 65 64 20 |ly; when| called |
|00001890| 77 69 74 68 20 61 20 66 | 69 6c 65 20 6e 61 6d 65 |with a f|ile name|
|000018a0| 20 61 72 67 75 6d 65 6e | 74 20 6f 72 20 77 69 74 | argumen|t or wit|
|000018b0| 68 0d 61 20 66 69 6c 65 | 20 61 73 20 73 74 61 6e |h.a file| as stan|
|000018c0| 64 61 72 64 20 69 6e 70 | 75 74 2c 20 69 74 20 72 |dard inp|ut, it r|
|000018d0| 65 61 64 73 20 61 6e 64 | 20 65 78 65 63 75 74 65 |eads and| execute|
|000018e0| 73 20 61 20 7b 5c 65 6d | 20 73 63 72 69 70 74 7d |s a {\em| script}|
|000018f0| 20 66 72 6f 6d 0d 74 68 | 61 74 20 66 69 6c 65 2e | from.th|at file.|
|00001900| 0d 0d 41 20 74 68 69 72 | 64 20 77 61 79 20 6f 66 |..A thir|d way of|
|00001910| 20 73 74 61 72 74 69 6e | 67 20 74 68 65 20 69 6e | startin|g the in|
|00001920| 74 65 72 70 72 65 74 65 | 72 20 69 73 0d 60 60 7b |terprete|r is.``{|
|00001930| 5c 74 74 20 70 79 74 68 | 6f 6e 20 2d 63 20 63 6f |\tt pyth|on -c co|
|00001940| 6d 6d 61 6e 64 20 5b 61 | 72 67 5d 20 2e 2e 2e 7d |mmand [a|rg] ...}|
|00001950| 27 27 2c 20 77 68 69 63 | 68 0d 65 78 65 63 75 74 |'', whic|h.execut|
|00001960| 65 73 20 74 68 65 20 73 | 74 61 74 65 6d 65 6e 74 |es the s|tatement|
|00001970| 28 73 29 20 69 6e 20 7b | 5c 74 74 20 63 6f 6d 6d |(s) in {|\tt comm|
|00001980| 61 6e 64 7d 2c 20 61 6e | 61 6c 6f 67 6f 75 73 20 |and}, an|alogous |
|00001990| 74 6f 20 74 68 65 20 73 | 68 65 6c 6c 27 73 0d 7b |to the s|hell's.{|
|000019a0| 5c 74 74 20 2d 63 7d 20 | 6f 70 74 69 6f 6e 2e 20 |\tt -c} |option. |
|000019b0| 20 53 69 6e 63 65 20 50 | 79 74 68 6f 6e 20 73 74 | Since P|ython st|
|000019c0| 61 74 65 6d 65 6e 74 73 | 20 6f 66 74 65 6e 20 63 |atements| often c|
|000019d0| 6f 6e 74 61 69 6e 20 73 | 70 61 63 65 73 20 6f 72 |ontain s|paces or|
|000019e0| 20 6f 74 68 65 72 0d 63 | 68 61 72 61 63 74 65 72 | other.c|haracter|
|000019f0| 73 20 74 68 61 74 20 61 | 72 65 20 73 70 65 63 69 |s that a|re speci|
|00001a00| 61 6c 20 74 6f 20 74 68 | 65 20 73 68 65 6c 6c 2c |al to th|e shell,|
|00001a10| 20 69 74 20 69 73 20 62 | 65 73 74 20 74 6f 20 71 | it is b|est to q|
|00001a20| 75 6f 74 65 20 7b 5c 74 | 74 0d 63 6f 6d 6d 61 6e |uote {\t|t.comman|
|00001a30| 64 7d 20 69 6e 20 69 74 | 73 20 65 6e 74 69 72 65 |d} in it|s entire|
|00001a40| 74 79 20 77 69 74 68 20 | 64 6f 75 62 6c 65 20 71 |ty with |double q|
|00001a50| 75 6f 74 65 73 2e 0d 0d | 4e 6f 74 65 20 74 68 61 |uotes...|Note tha|
|00001a60| 74 20 74 68 65 72 65 20 | 69 73 20 61 20 64 69 66 |t there |is a dif|
|00001a70| 66 65 72 65 6e 63 65 20 | 62 65 74 77 65 65 6e 20 |ference |between |
|00001a80| 60 60 7b 5c 74 74 20 70 | 79 74 68 6f 6e 20 66 69 |``{\tt p|ython fi|
|00001a90| 6c 65 7d 27 27 20 61 6e | 64 0d 60 60 7b 5c 74 74 |le}'' an|d.``{\tt|
|00001aa0| 20 70 79 74 68 6f 6e 20 | 24 3c 24 66 69 6c 65 7d | python |$<$file}|
|00001ab0| 27 27 2e 20 20 49 6e 20 | 74 68 65 20 6c 61 74 74 |''. In |the latt|
|00001ac0| 65 72 20 63 61 73 65 2c | 20 69 6e 70 75 74 20 72 |er case,| input r|
|00001ad0| 65 71 75 65 73 74 73 20 | 66 72 6f 6d 20 74 68 65 |equests |from the|
|00001ae0| 0d 70 72 6f 67 72 61 6d | 2c 20 73 75 63 68 20 61 |.program|, such a|
|00001af0| 73 20 63 61 6c 6c 73 20 | 74 6f 20 7b 5c 74 74 20 |s calls |to {\tt |
|00001b00| 69 6e 70 75 74 28 29 7d | 20 61 6e 64 20 7b 5c 74 |input()}| and {\t|
|00001b10| 74 20 72 61 77 5f 69 6e | 70 75 74 28 29 7d 2c 20 |t raw_in|put()}, |
|00001b20| 61 72 65 0d 73 61 74 69 | 73 66 69 65 64 20 66 72 |are.sati|sfied fr|
|00001b30| 6f 6d 20 7b 5c 65 6d 20 | 66 69 6c 65 7d 2e 20 20 |om {\em |file}. |
|00001b40| 53 69 6e 63 65 20 74 68 | 69 73 20 66 69 6c 65 20 |Since th|is file |
|00001b50| 68 61 73 20 61 6c 72 65 | 61 64 79 20 62 65 65 6e |has alre|ady been|
|00001b60| 20 72 65 61 64 0d 75 6e | 74 69 6c 20 74 68 65 20 | read.un|til the |
|00001b70| 65 6e 64 20 62 79 20 74 | 68 65 20 70 61 72 73 65 |end by t|he parse|
|00001b80| 72 20 62 65 66 6f 72 65 | 20 74 68 65 20 70 72 6f |r before| the pro|
|00001b90| 67 72 61 6d 20 73 74 61 | 72 74 73 20 65 78 65 63 |gram sta|rts exec|
|00001ba0| 75 74 69 6e 67 2c 20 74 | 68 65 0d 70 72 6f 67 72 |uting, t|he.progr|
|00001bb0| 61 6d 20 77 69 6c 6c 20 | 65 6e 63 6f 75 6e 74 65 |am will |encounte|
|00001bc0| 72 20 45 4f 46 20 69 6d | 6d 65 64 69 61 74 65 6c |r EOF im|mediatel|
|00001bd0| 79 2e 20 20 49 6e 20 74 | 68 65 20 66 6f 72 6d 65 |y. In t|he forme|
|00001be0| 72 20 63 61 73 65 20 28 | 77 68 69 63 68 20 69 73 |r case (|which is|
|00001bf0| 0d 75 73 75 61 6c 6c 79 | 20 77 68 61 74 20 79 6f |.usually| what yo|
|00001c00| 75 20 77 61 6e 74 29 20 | 74 68 65 79 20 61 72 65 |u want) |they are|
|00001c10| 20 73 61 74 69 73 66 69 | 65 64 20 66 72 6f 6d 20 | satisfi|ed from |
|00001c20| 77 68 61 74 65 76 65 72 | 20 66 69 6c 65 20 6f 72 |whatever| file or|
|00001c30| 20 64 65 76 69 63 65 0d | 69 73 20 63 6f 6e 6e 65 | device.|is conne|
|00001c40| 63 74 65 64 20 74 6f 20 | 73 74 61 6e 64 61 72 64 |cted to |standard|
|00001c50| 20 69 6e 70 75 74 20 6f | 66 20 74 68 65 20 50 79 | input o|f the Py|
|00001c60| 74 68 6f 6e 20 69 6e 74 | 65 72 70 72 65 74 65 72 |thon int|erpreter|
|00001c70| 2e 0d 0d 57 68 65 6e 20 | 61 20 73 63 72 69 70 74 |...When |a script|
|00001c80| 20 66 69 6c 65 20 69 73 | 20 75 73 65 64 2c 20 69 | file is| used, i|
|00001c90| 74 20 69 73 20 73 6f 6d | 65 74 69 6d 65 73 20 75 |t is som|etimes u|
|00001ca0| 73 65 66 75 6c 20 74 6f | 20 62 65 20 61 62 6c 65 |seful to| be able|
|00001cb0| 20 74 6f 20 72 75 6e 0d | 74 68 65 20 73 63 72 69 | to run.|the scri|
|00001cc0| 70 74 20 61 6e 64 20 65 | 6e 74 65 72 20 69 6e 74 |pt and e|nter int|
|00001cd0| 65 72 61 63 74 69 76 65 | 20 6d 6f 64 65 20 61 66 |eractive| mode af|
|00001ce0| 74 65 72 77 61 72 64 73 | 2e 20 20 54 68 69 73 20 |terwards|. This |
|00001cf0| 63 61 6e 20 62 65 20 64 | 6f 6e 65 20 62 79 0d 70 |can be d|one by.p|
|00001d00| 61 73 73 69 6e 67 20 7b | 5c 74 74 20 2d 69 7d 20 |assing {|\tt -i} |
|00001d10| 62 65 66 6f 72 65 20 74 | 68 65 20 73 63 72 69 70 |before t|he scrip|
|00001d20| 74 2e 20 20 28 54 68 69 | 73 20 64 6f 65 73 20 6e |t. (Thi|s does n|
|00001d30| 6f 74 20 77 6f 72 6b 20 | 69 66 20 74 68 65 20 73 |ot work |if the s|
|00001d40| 63 72 69 70 74 0d 69 73 | 20 72 65 61 64 20 66 72 |cript.is| read fr|
|00001d50| 6f 6d 20 73 74 61 6e 64 | 61 72 64 20 69 6e 70 75 |om stand|ard inpu|
|00001d60| 74 2c 20 66 6f 72 20 74 | 68 65 20 73 61 6d 65 20 |t, for t|he same |
|00001d70| 72 65 61 73 6f 6e 20 61 | 73 20 65 78 70 6c 61 69 |reason a|s explai|
|00001d80| 6e 65 64 20 69 6e 20 74 | 68 65 0d 70 72 65 76 69 |ned in t|he.previ|
|00001d90| 6f 75 73 20 70 61 72 61 | 67 72 61 70 68 2e 29 0d |ous para|graph.).|
|00001da0| 0d 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 41 72 67 |.\subsec|tion{Arg|
|00001db0| 75 6d 65 6e 74 20 50 61 | 73 73 69 6e 67 7d 0d 0d |ument Pa|ssing}..|
|00001dc0| 57 68 65 6e 20 6b 6e 6f | 77 6e 20 74 6f 20 74 68 |When kno|wn to th|
|00001dd0| 65 20 69 6e 74 65 72 70 | 72 65 74 65 72 2c 20 74 |e interp|reter, t|
|00001de0| 68 65 20 73 63 72 69 70 | 74 20 6e 61 6d 65 20 61 |he scrip|t name a|
|00001df0| 6e 64 20 61 64 64 69 74 | 69 6f 6e 61 6c 0d 61 72 |nd addit|ional.ar|
|00001e00| 67 75 6d 65 6e 74 73 20 | 74 68 65 72 65 61 66 74 |guments |thereaft|
|00001e10| 65 72 20 61 72 65 20 70 | 61 73 73 65 64 20 74 6f |er are p|assed to|
|00001e20| 20 74 68 65 20 73 63 72 | 69 70 74 20 69 6e 20 74 | the scr|ipt in t|
|00001e30| 68 65 20 76 61 72 69 61 | 62 6c 65 20 7b 5c 74 74 |he varia|ble {\tt|
|00001e40| 0d 73 79 73 2e 61 72 67 | 76 7d 2c 20 77 68 69 63 |.sys.arg|v}, whic|
|00001e50| 68 20 69 73 20 61 20 6c | 69 73 74 20 6f 66 20 73 |h is a l|ist of s|
|00001e60| 74 72 69 6e 67 73 2e 20 | 20 49 74 73 20 6c 65 6e |trings. | Its len|
|00001e70| 67 74 68 20 69 73 20 61 | 74 20 6c 65 61 73 74 20 |gth is a|t least |
|00001e80| 6f 6e 65 3b 0d 77 68 65 | 6e 20 6e 6f 20 73 63 72 |one;.whe|n no scr|
|00001e90| 69 70 74 20 61 6e 64 20 | 6e 6f 20 61 72 67 75 6d |ipt and |no argum|
|00001ea0| 65 6e 74 73 20 61 72 65 | 20 67 69 76 65 6e 2c 20 |ents are| given, |
|00001eb0| 7b 5c 74 74 20 73 79 73 | 2e 61 72 67 76 5b 30 5d |{\tt sys|.argv[0]|
|00001ec0| 7d 20 69 73 20 61 6e 0d | 65 6d 70 74 79 20 73 74 |} is an.|empty st|
|00001ed0| 72 69 6e 67 2e 20 20 57 | 68 65 6e 20 74 68 65 20 |ring. W|hen the |
|00001ee0| 73 63 72 69 70 74 20 6e | 61 6d 65 20 69 73 20 67 |script n|ame is g|
|00001ef0| 69 76 65 6e 20 61 73 20 | 7b 5c 74 74 20 27 2d 27 |iven as |{\tt '-'|
|00001f00| 7d 20 28 6d 65 61 6e 69 | 6e 67 0d 73 74 61 6e 64 |} (meani|ng.stand|
|00001f10| 61 72 64 20 69 6e 70 75 | 74 29 2c 20 7b 5c 74 74 |ard inpu|t), {\tt|
|00001f20| 20 73 79 73 2e 61 72 67 | 76 5b 30 5d 7d 20 69 73 | sys.arg|v[0]} is|
|00001f30| 20 73 65 74 20 74 6f 20 | 7b 5c 74 74 20 27 2d 27 | set to |{\tt '-'|
|00001f40| 7d 2e 20 20 57 68 65 6e | 20 7b 5c 74 74 20 2d 63 |}. When| {\tt -c|
|00001f50| 0d 63 6f 6d 6d 61 6e 64 | 7d 20 69 73 20 75 73 65 |.command|} is use|
|00001f60| 64 2c 20 7b 5c 74 74 20 | 73 79 73 2e 61 72 67 76 |d, {\tt |sys.argv|
|00001f70| 5b 30 5d 7d 20 69 73 20 | 73 65 74 20 74 6f 20 7b |[0]} is |set to {|
|00001f80| 5c 74 74 20 27 2d 63 27 | 7d 2e 20 20 4f 70 74 69 |\tt '-c'|}. Opti|
|00001f90| 6f 6e 73 0d 66 6f 75 6e | 64 20 61 66 74 65 72 20 |ons.foun|d after |
|00001fa0| 7b 5c 74 74 20 2d 63 20 | 63 6f 6d 6d 61 6e 64 7d |{\tt -c |command}|
|00001fb0| 20 61 72 65 20 6e 6f 74 | 20 63 6f 6e 73 75 6d 65 | are not| consume|
|00001fc0| 64 20 62 79 20 74 68 65 | 20 50 79 74 68 6f 6e 0d |d by the| Python.|
|00001fd0| 69 6e 74 65 72 70 72 65 | 74 65 72 27 73 20 6f 70 |interpre|ter's op|
|00001fe0| 74 69 6f 6e 20 70 72 6f | 63 65 73 73 69 6e 67 20 |tion pro|cessing |
|00001ff0| 62 75 74 20 6c 65 66 74 | 20 69 6e 20 7b 5c 74 74 |but left| in {\tt|
|00002000| 20 73 79 73 2e 61 72 67 | 76 7d 20 66 6f 72 20 74 | sys.arg|v} for t|
|00002010| 68 65 0d 63 6f 6d 6d 61 | 6e 64 20 74 6f 20 68 61 |he.comma|nd to ha|
|00002020| 6e 64 6c 65 2e 0d 0d 5c | 73 75 62 73 65 63 74 69 |ndle...\|subsecti|
|00002030| 6f 6e 7b 49 6e 74 65 72 | 61 63 74 69 76 65 20 4d |on{Inter|active M|
|00002040| 6f 64 65 7d 0d 0d 57 68 | 65 6e 20 63 6f 6d 6d 61 |ode}..Wh|en comma|
|00002050| 6e 64 73 20 61 72 65 20 | 72 65 61 64 20 66 72 6f |nds are |read fro|
|00002060| 6d 20 61 20 74 74 79 2c | 20 74 68 65 20 69 6e 74 |m a tty,| the int|
|00002070| 65 72 70 72 65 74 65 72 | 20 69 73 20 73 61 69 64 |erpreter| is said|
|00002080| 20 74 6f 20 62 65 20 69 | 6e 0d 7b 5c 65 6d 20 69 | to be i|n.{\em i|
|00002090| 6e 74 65 72 61 63 74 69 | 76 65 5c 20 6d 6f 64 65 |nteracti|ve\ mode|
|000020a0| 7d 2e 20 20 49 6e 20 74 | 68 69 73 20 6d 6f 64 65 |}. In t|his mode|
|000020b0| 20 69 74 20 70 72 6f 6d | 70 74 73 20 66 6f 72 20 | it prom|pts for |
|000020c0| 74 68 65 20 6e 65 78 74 | 20 63 6f 6d 6d 61 6e 64 |the next| command|
|000020d0| 0d 77 69 74 68 20 74 68 | 65 20 7b 5c 65 6d 20 70 |.with th|e {\em p|
|000020e0| 72 69 6d 61 72 79 5c 20 | 70 72 6f 6d 70 74 7d 2c |rimary\ |prompt},|
|000020f0| 20 75 73 75 61 6c 6c 79 | 20 74 68 72 65 65 20 67 | usually| three g|
|00002100| 72 65 61 74 65 72 2d 74 | 68 61 6e 20 73 69 67 6e |reater-t|han sign|
|00002110| 73 20 28 7b 5c 74 74 0d | 3e 3e 3e 7d 29 3b 20 66 |s ({\tt.|>>>}); f|
|00002120| 6f 72 20 63 6f 6e 74 69 | 6e 75 61 74 69 6f 6e 20 |or conti|nuation |
|00002130| 6c 69 6e 65 73 20 69 74 | 20 70 72 6f 6d 70 74 73 |lines it| prompts|
|00002140| 20 77 69 74 68 20 74 68 | 65 20 7b 5c 65 6d 20 73 | with th|e {\em s|
|00002150| 65 63 6f 6e 64 61 72 79 | 5c 0d 70 72 6f 6d 70 74 |econdary|\.prompt|
|00002160| 7d 2c 20 62 79 20 64 65 | 66 61 75 6c 74 20 74 68 |}, by de|fault th|
|00002170| 72 65 65 20 64 6f 74 73 | 20 28 7b 5c 74 74 20 2e |ree dots| ({\tt .|
|00002180| 2e 2e 7d 29 2e 20 20 54 | 79 70 69 6e 67 20 61 6e |..}). T|yping an|
|00002190| 20 45 4f 46 20 28 43 6f | 6e 74 72 6f 6c 2d 44 29 | EOF (Co|ntrol-D)|
|000021a0| 0d 61 74 20 74 68 65 20 | 70 72 69 6d 61 72 79 20 |.at the |primary |
|000021b0| 70 72 6f 6d 70 74 20 63 | 61 75 73 65 73 20 74 68 |prompt c|auses th|
|000021c0| 65 20 69 6e 74 65 72 70 | 72 65 74 65 72 20 74 6f |e interp|reter to|
|000021d0| 20 65 78 69 74 20 77 69 | 74 68 20 61 20 7a 65 72 | exit wi|th a zer|
|000021e0| 6f 20 65 78 69 74 0d 73 | 74 61 74 75 73 2e 0d 0d |o exit.s|tatus...|
|000021f0| 54 68 65 20 69 6e 74 65 | 72 70 72 65 74 65 72 20 |The inte|rpreter |
|00002200| 70 72 69 6e 74 73 20 61 | 20 77 65 6c 63 6f 6d 65 |prints a| welcome|
|00002210| 20 6d 65 73 73 61 67 65 | 20 73 74 61 74 69 6e 67 | message| stating|
|00002220| 20 69 74 73 20 76 65 72 | 73 69 6f 6e 20 6e 75 6d | its ver|sion num|
|00002230| 62 65 72 0d 61 6e 64 20 | 61 20 63 6f 70 79 72 69 |ber.and |a copyri|
|00002240| 67 68 74 20 6e 6f 74 69 | 63 65 20 62 65 66 6f 72 |ght noti|ce befor|
|00002250| 65 20 70 72 69 6e 74 69 | 6e 67 20 74 68 65 20 66 |e printi|ng the f|
|00002260| 69 72 73 74 20 70 72 6f | 6d 70 74 2c 20 65 2e 67 |irst pro|mpt, e.g|
|00002270| 2e 3a 0d 0d 5c 62 63 6f | 64 65 5c 62 65 67 69 6e |.:..\bco|de\begin|
|00002280| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 70 79 74 68 6f |{verbati|m}.pytho|
|00002290| 6e 0d 50 79 74 68 6f 6e | 20 31 2e 31 20 28 4f 63 |n.Python| 1.1 (Oc|
|000022a0| 74 20 20 36 20 31 39 39 | 34 29 0d 43 6f 70 79 72 |t 6 199|4).Copyr|
|000022b0| 69 67 68 74 20 31 39 39 | 31 2d 31 39 39 34 20 53 |ight 199|1-1994 S|
|000022c0| 74 69 63 68 74 69 6e 67 | 20 4d 61 74 68 65 6d 61 |tichting| Mathema|
|000022d0| 74 69 73 63 68 20 43 65 | 6e 74 72 75 6d 2c 20 41 |tisch Ce|ntrum, A|
|000022e0| 6d 73 74 65 72 64 61 6d | 0d 3e 3e 3e 0d 5c 65 6e |msterdam|.>>>.\en|
|000022f0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00002300| 65 0d 0d 5c 73 65 63 74 | 69 6f 6e 7b 54 68 65 20 |e..\sect|ion{The |
|00002310| 49 6e 74 65 72 70 72 65 | 74 65 72 20 61 6e 64 20 |Interpre|ter and |
|00002320| 69 74 73 20 45 6e 76 69 | 72 6f 6e 6d 65 6e 74 7d |its Envi|ronment}|
|00002330| 0d 0d 5c 73 75 62 73 65 | 63 74 69 6f 6e 7b 45 72 |..\subse|ction{Er|
|00002340| 72 6f 72 20 48 61 6e 64 | 6c 69 6e 67 7d 0d 0d 57 |ror Hand|ling}..W|
|00002350| 68 65 6e 20 61 6e 20 65 | 72 72 6f 72 20 6f 63 63 |hen an e|rror occ|
|00002360| 75 72 73 2c 20 74 68 65 | 20 69 6e 74 65 72 70 72 |urs, the| interpr|
|00002370| 65 74 65 72 20 70 72 69 | 6e 74 73 20 61 6e 20 65 |eter pri|nts an e|
|00002380| 72 72 6f 72 0d 6d 65 73 | 73 61 67 65 20 61 6e 64 |rror.mes|sage and|
|00002390| 20 61 20 73 74 61 63 6b | 20 74 72 61 63 65 2e 20 | a stack| trace. |
|000023a0| 20 49 6e 20 69 6e 74 65 | 72 61 63 74 69 76 65 20 | In inte|ractive |
|000023b0| 6d 6f 64 65 2c 20 69 74 | 20 74 68 65 6e 20 72 65 |mode, it| then re|
|000023c0| 74 75 72 6e 73 20 74 6f | 0d 74 68 65 20 70 72 69 |turns to|.the pri|
|000023d0| 6d 61 72 79 20 70 72 6f | 6d 70 74 3b 20 77 68 65 |mary pro|mpt; whe|
|000023e0| 6e 20 69 6e 70 75 74 20 | 63 61 6d 65 20 66 72 6f |n input |came fro|
|000023f0| 6d 20 61 20 66 69 6c 65 | 2c 20 69 74 20 65 78 69 |m a file|, it exi|
|00002400| 74 73 20 77 69 74 68 20 | 61 0d 6e 6f 6e 7a 65 72 |ts with |a.nonzer|
|00002410| 6f 20 65 78 69 74 20 73 | 74 61 74 75 73 20 61 66 |o exit s|tatus af|
|00002420| 74 65 72 20 70 72 69 6e | 74 69 6e 67 0d 74 68 65 |ter prin|ting.the|
|00002430| 20 73 74 61 63 6b 20 74 | 72 61 63 65 2e 20 20 28 | stack t|race. (|
|00002440| 45 78 63 65 70 74 69 6f | 6e 73 20 68 61 6e 64 6c |Exceptio|ns handl|
|00002450| 65 64 20 62 79 20 61 6e | 20 7b 5c 74 74 20 65 78 |ed by an| {\tt ex|
|00002460| 63 65 70 74 7d 20 63 6c | 61 75 73 65 20 69 6e 20 |cept} cl|ause in |
|00002470| 61 0d 7b 5c 74 74 20 74 | 72 79 7d 20 73 74 61 74 |a.{\tt t|ry} stat|
|00002480| 65 6d 65 6e 74 20 61 72 | 65 20 6e 6f 74 20 65 72 |ement ar|e not er|
|00002490| 72 6f 72 73 20 69 6e 20 | 74 68 69 73 20 63 6f 6e |rors in |this con|
|000024a0| 74 65 78 74 2e 29 20 20 | 53 6f 6d 65 20 65 72 72 |text.) |Some err|
|000024b0| 6f 72 73 20 61 72 65 0d | 75 6e 63 6f 6e 64 69 74 |ors are.|uncondit|
|000024c0| 69 6f 6e 61 6c 6c 79 20 | 66 61 74 61 6c 20 61 6e |ionally |fatal an|
|000024d0| 64 20 63 61 75 73 65 20 | 61 6e 20 65 78 69 74 20 |d cause |an exit |
|000024e0| 77 69 74 68 20 61 20 6e | 6f 6e 7a 65 72 6f 20 65 |with a n|onzero e|
|000024f0| 78 69 74 3b 20 74 68 69 | 73 0d 61 70 70 6c 69 65 |xit; thi|s.applie|
|00002500| 73 20 74 6f 20 69 6e 74 | 65 72 6e 61 6c 20 69 6e |s to int|ernal in|
|00002510| 63 6f 6e 73 69 73 74 65 | 6e 63 69 65 73 20 61 6e |consiste|ncies an|
|00002520| 64 20 73 6f 6d 65 20 63 | 61 73 65 73 20 6f 66 20 |d some c|ases of |
|00002530| 72 75 6e 6e 69 6e 67 20 | 6f 75 74 20 6f 66 0d 6d |running |out of.m|
|00002540| 65 6d 6f 72 79 2e 20 20 | 41 6c 6c 20 65 72 72 6f |emory. |All erro|
|00002550| 72 20 6d 65 73 73 61 67 | 65 73 20 61 72 65 20 77 |r messag|es are w|
|00002560| 72 69 74 74 65 6e 20 74 | 6f 20 74 68 65 20 73 74 |ritten t|o the st|
|00002570| 61 6e 64 61 72 64 20 65 | 72 72 6f 72 20 73 74 72 |andard e|rror str|
|00002580| 65 61 6d 3b 0d 6e 6f 72 | 6d 61 6c 20 6f 75 74 70 |eam;.nor|mal outp|
|00002590| 75 74 20 66 72 6f 6d 20 | 74 68 65 20 65 78 65 63 |ut from |the exec|
|000025a0| 75 74 65 64 20 63 6f 6d | 6d 61 6e 64 73 20 69 73 |uted com|mands is|
|000025b0| 20 77 72 69 74 74 65 6e | 20 74 6f 20 73 74 61 6e | written| to stan|
|000025c0| 64 61 72 64 0d 6f 75 74 | 70 75 74 2e 0d 0d 54 79 |dard.out|put...Ty|
|000025d0| 70 69 6e 67 20 74 68 65 | 20 69 6e 74 65 72 72 75 |ping the| interru|
|000025e0| 70 74 20 63 68 61 72 61 | 63 74 65 72 20 28 75 73 |pt chara|cter (us|
|000025f0| 75 61 6c 6c 79 20 43 6f | 6e 74 72 6f 6c 2d 43 20 |ually Co|ntrol-C |
|00002600| 6f 72 20 44 45 4c 29 20 | 74 6f 20 74 68 65 0d 70 |or DEL) |to the.p|
|00002610| 72 69 6d 61 72 79 20 6f | 72 20 73 65 63 6f 6e 64 |rimary o|r second|
|00002620| 61 72 79 20 70 72 6f 6d | 70 74 20 63 61 6e 63 65 |ary prom|pt cance|
|00002630| 6c 73 20 74 68 65 20 69 | 6e 70 75 74 20 61 6e 64 |ls the i|nput and|
|00002640| 20 72 65 74 75 72 6e 73 | 20 74 6f 20 74 68 65 0d | returns| to the.|
|00002650| 70 72 69 6d 61 72 79 20 | 70 72 6f 6d 70 74 2e 25 |primary |prompt.%|
|00002660| 0d 5c 66 6f 6f 74 6e 6f | 74 65 7b 0d 20 20 20 20 |.\footno|te{. |
|00002670| 20 20 20 20 41 20 70 72 | 6f 62 6c 65 6d 20 77 69 | A pr|oblem wi|
|00002680| 74 68 20 74 68 65 20 47 | 4e 55 20 52 65 61 64 6c |th the G|NU Readl|
|00002690| 69 6e 65 20 70 61 63 6b | 61 67 65 20 6d 61 79 20 |ine pack|age may |
|000026a0| 70 72 65 76 65 6e 74 20 | 74 68 69 73 2e 0d 7d 0d |prevent |this..}.|
|000026b0| 54 79 70 69 6e 67 20 61 | 6e 20 69 6e 74 65 72 72 |Typing a|n interr|
|000026c0| 75 70 74 20 77 68 69 6c | 65 20 61 20 63 6f 6d 6d |upt whil|e a comm|
|000026d0| 61 6e 64 20 69 73 20 65 | 78 65 63 75 74 69 6e 67 |and is e|xecuting|
|000026e0| 20 72 61 69 73 65 73 20 | 74 68 65 20 7b 5c 74 74 | raises |the {\tt|
|000026f0| 0d 4b 65 79 62 6f 61 72 | 64 49 6e 74 65 72 72 75 |.Keyboar|dInterru|
|00002700| 70 74 7d 20 65 78 63 65 | 70 74 69 6f 6e 2c 20 77 |pt} exce|ption, w|
|00002710| 68 69 63 68 20 6d 61 79 | 20 62 65 20 68 61 6e 64 |hich may| be hand|
|00002720| 6c 65 64 20 62 79 20 61 | 20 7b 5c 74 74 20 74 72 |led by a| {\tt tr|
|00002730| 79 7d 0d 73 74 61 74 65 | 6d 65 6e 74 2e 0d 0d 5c |y}.state|ment...\|
|00002740| 73 75 62 73 65 63 74 69 | 6f 6e 7b 54 68 65 20 4d |subsecti|on{The M|
|00002750| 6f 64 75 6c 65 20 53 65 | 61 72 63 68 20 50 61 74 |odule Se|arch Pat|
|00002760| 68 7d 0d 0d 57 68 65 6e | 20 61 20 6d 6f 64 75 6c |h}..When| a modul|
|00002770| 65 20 6e 61 6d 65 64 20 | 7b 5c 74 74 20 66 6f 6f |e named |{\tt foo|
|00002780| 7d 20 69 73 20 69 6d 70 | 6f 72 74 65 64 2c 20 74 |} is imp|orted, t|
|00002790| 68 65 20 69 6e 74 65 72 | 70 72 65 74 65 72 20 73 |he inter|preter s|
|000027a0| 65 61 72 63 68 65 73 0d | 66 6f 72 20 61 20 66 69 |earches.|for a fi|
|000027b0| 6c 65 20 6e 61 6d 65 64 | 20 7b 5c 74 74 20 66 6f |le named| {\tt fo|
|000027c0| 6f 2e 70 79 7d 20 69 6e | 20 74 68 65 20 6c 69 73 |o.py} in| the lis|
|000027d0| 74 20 6f 66 20 64 69 72 | 65 63 74 6f 72 69 65 73 |t of dir|ectories|
|000027e0| 20 73 70 65 63 69 66 69 | 65 64 20 62 79 0d 74 68 | specifi|ed by.th|
|000027f0| 65 20 65 6e 76 69 72 6f | 6e 6d 65 6e 74 20 76 61 |e enviro|nment va|
|00002800| 72 69 61 62 6c 65 20 7b | 5c 74 74 20 50 59 54 48 |riable {|\tt PYTH|
|00002810| 4f 4e 50 41 54 48 7d 2e | 20 20 49 74 20 68 61 73 |ONPATH}.| It has|
|00002820| 20 74 68 65 20 73 61 6d | 65 20 73 79 6e 74 61 78 | the sam|e syntax|
|00002830| 20 61 73 0d 74 68 65 20 | 7b 5c 55 4e 49 58 7d 20 | as.the |{\UNIX} |
|00002840| 73 68 65 6c 6c 20 76 61 | 72 69 61 62 6c 65 20 7b |shell va|riable {|
|00002850| 5c 74 74 20 50 41 54 48 | 7d 2c 20 69 2e 65 2e 2c |\tt PATH|}, i.e.,|
|00002860| 20 61 20 6c 69 73 74 20 | 6f 66 20 63 6f 6c 6f 6e | a list |of colon|
|00002870| 2d 73 65 70 61 72 61 74 | 65 64 0d 64 69 72 65 63 |-separat|ed.direc|
|00002880| 74 6f 72 79 20 6e 61 6d | 65 73 2e 20 20 57 68 65 |tory nam|es. Whe|
|00002890| 6e 20 7b 5c 74 74 20 50 | 59 54 48 4f 4e 50 41 54 |n {\tt P|YTHONPAT|
|000028a0| 48 7d 20 69 73 20 6e 6f | 74 20 73 65 74 2c 20 6f |H} is no|t set, o|
|000028b0| 72 20 77 68 65 6e 20 74 | 68 65 20 66 69 6c 65 0d |r when t|he file.|
|000028c0| 69 73 20 6e 6f 74 20 66 | 6f 75 6e 64 20 74 68 65 |is not f|ound the|
|000028d0| 72 65 2c 20 74 68 65 20 | 73 65 61 72 63 68 20 63 |re, the |search c|
|000028e0| 6f 6e 74 69 6e 75 65 73 | 20 69 6e 20 61 6e 20 69 |ontinues| in an i|
|000028f0| 6e 73 74 61 6c 6c 61 74 | 69 6f 6e 2d 64 65 70 65 |nstallat|ion-depe|
|00002900| 6e 64 65 6e 74 0d 64 65 | 66 61 75 6c 74 20 70 61 |ndent.de|fault pa|
|00002910| 74 68 2c 20 75 73 75 61 | 6c 6c 79 20 7b 5c 74 74 |th, usua|lly {\tt|
|00002920| 20 2e 3a 2f 75 73 72 2f | 6c 6f 63 61 6c 2f 6c 69 | .:/usr/|local/li|
|00002930| 62 2f 70 79 74 68 6f 6e | 7d 2e 0d 0d 41 63 74 75 |b/python|}...Actu|
|00002940| 61 6c 6c 79 2c 20 6d 6f | 64 75 6c 65 73 20 61 72 |ally, mo|dules ar|
|00002950| 65 20 73 65 61 72 63 68 | 65 64 20 69 6e 20 74 68 |e search|ed in th|
|00002960| 65 20 6c 69 73 74 20 6f | 66 20 64 69 72 65 63 74 |e list o|f direct|
|00002970| 6f 72 69 65 73 20 67 69 | 76 65 6e 20 62 79 20 74 |ories gi|ven by t|
|00002980| 68 65 0d 76 61 72 69 61 | 62 6c 65 20 7b 5c 74 74 |he.varia|ble {\tt|
|00002990| 20 73 79 73 2e 70 61 74 | 68 7d 20 77 68 69 63 68 | sys.pat|h} which|
|000029a0| 20 69 73 20 69 6e 69 74 | 69 61 6c 69 7a 65 64 20 | is init|ialized |
|000029b0| 66 72 6f 6d 20 7b 5c 74 | 74 20 50 59 54 48 4f 4e |from {\t|t PYTHON|
|000029c0| 50 41 54 48 7d 20 61 6e | 64 0d 74 68 65 20 69 6e |PATH} an|d.the in|
|000029d0| 73 74 61 6c 6c 61 74 69 | 6f 6e 2d 64 65 70 65 6e |stallati|on-depen|
|000029e0| 64 65 6e 74 20 64 65 66 | 61 75 6c 74 2e 20 20 54 |dent def|ault. T|
|000029f0| 68 69 73 20 61 6c 6c 6f | 77 73 20 50 79 74 68 6f |his allo|ws Pytho|
|00002a00| 6e 20 70 72 6f 67 72 61 | 6d 73 20 74 68 61 74 0d |n progra|ms that.|
|00002a10| 6b 6e 6f 77 20 77 68 61 | 74 20 74 68 65 79 27 72 |know wha|t they'r|
|00002a20| 65 20 64 6f 69 6e 67 20 | 74 6f 20 6d 6f 64 69 66 |e doing |to modif|
|00002a30| 79 20 6f 72 20 72 65 70 | 6c 61 63 65 20 74 68 65 |y or rep|lace the|
|00002a40| 20 6d 6f 64 75 6c 65 20 | 73 65 61 72 63 68 20 70 | module |search p|
|00002a50| 61 74 68 2e 0d 53 65 65 | 20 74 68 65 20 73 65 63 |ath..See| the sec|
|00002a60| 74 69 6f 6e 20 6f 6e 20 | 53 74 61 6e 64 61 72 64 |tion on |Standard|
|00002a70| 20 4d 6f 64 75 6c 65 73 | 20 6c 61 74 65 72 2e 0d | Modules| later..|
|00002a80| 0d 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 60 60 43 |.\subsec|tion{``C|
|00002a90| 6f 6d 70 69 6c 65 64 27 | 27 20 50 79 74 68 6f 6e |ompiled'|' Python|
|00002aa0| 20 66 69 6c 65 73 7d 0d | 0d 41 73 20 61 6e 20 69 | files}.|.As an i|
|00002ab0| 6d 70 6f 72 74 61 6e 74 | 20 73 70 65 65 64 2d 75 |mportant| speed-u|
|00002ac0| 70 20 6f 66 20 74 68 65 | 20 73 74 61 72 74 2d 75 |p of the| start-u|
|00002ad0| 70 20 74 69 6d 65 20 66 | 6f 72 20 73 68 6f 72 74 |p time f|or short|
|00002ae0| 20 70 72 6f 67 72 61 6d | 73 20 74 68 61 74 0d 75 | program|s that.u|
|00002af0| 73 65 20 61 20 6c 6f 74 | 20 6f 66 20 73 74 61 6e |se a lot| of stan|
|00002b00| 64 61 72 64 20 6d 6f 64 | 75 6c 65 73 2c 20 69 66 |dard mod|ules, if|
|00002b10| 20 61 20 66 69 6c 65 20 | 63 61 6c 6c 65 64 20 7b | a file |called {|
|00002b20| 5c 74 74 20 66 6f 6f 2e | 70 79 63 7d 20 65 78 69 |\tt foo.|pyc} exi|
|00002b30| 73 74 73 0d 69 6e 20 74 | 68 65 20 64 69 72 65 63 |sts.in t|he direc|
|00002b40| 74 6f 72 79 20 77 68 65 | 72 65 20 7b 5c 74 74 20 |tory whe|re {\tt |
|00002b50| 66 6f 6f 2e 70 79 7d 20 | 69 73 20 66 6f 75 6e 64 |foo.py} |is found|
|00002b60| 2c 20 74 68 69 73 20 69 | 73 20 61 73 73 75 6d 65 |, this i|s assume|
|00002b70| 64 20 74 6f 0d 63 6f 6e | 74 61 69 6e 20 61 6e 20 |d to.con|tain an |
|00002b80| 61 6c 72 65 61 64 79 2d | 60 60 63 6f 6d 70 69 6c |already-|``compil|
|00002b90| 65 64 27 27 20 76 65 72 | 73 69 6f 6e 20 6f 66 20 |ed'' ver|sion of |
|00002ba0| 74 68 65 20 6d 6f 64 75 | 6c 65 20 7b 5c 74 74 20 |the modu|le {\tt |
|00002bb0| 66 6f 6f 7d 2e 20 20 54 | 68 65 0d 6d 6f 64 69 66 |foo}. T|he.modif|
|00002bc0| 69 63 61 74 69 6f 6e 20 | 74 69 6d 65 20 6f 66 20 |ication |time of |
|00002bd0| 74 68 65 20 76 65 72 73 | 69 6f 6e 20 6f 66 20 7b |the vers|ion of {|
|00002be0| 5c 74 74 20 66 6f 6f 2e | 70 79 7d 20 75 73 65 64 |\tt foo.|py} used|
|00002bf0| 20 74 6f 20 63 72 65 61 | 74 65 20 7b 5c 74 74 0d | to crea|te {\tt.|
|00002c00| 66 6f 6f 2e 70 79 63 7d | 20 69 73 20 72 65 63 6f |foo.pyc}| is reco|
|00002c10| 72 64 65 64 20 69 6e 20 | 7b 5c 74 74 20 66 6f 6f |rded in |{\tt foo|
|00002c20| 2e 70 79 63 7d 2c 20 61 | 6e 64 20 74 68 65 20 66 |.pyc}, a|nd the f|
|00002c30| 69 6c 65 20 69 73 20 69 | 67 6e 6f 72 65 64 20 69 |ile is i|gnored i|
|00002c40| 66 0d 74 68 65 73 65 20 | 64 6f 6e 27 74 20 6d 61 |f.these |don't ma|
|00002c50| 74 63 68 2e 0d 0d 57 68 | 65 6e 65 76 65 72 20 7b |tch...Wh|enever {|
|00002c60| 5c 74 74 20 66 6f 6f 2e | 70 79 7d 20 69 73 20 73 |\tt foo.|py} is s|
|00002c70| 75 63 63 65 73 73 66 75 | 6c 6c 79 20 63 6f 6d 70 |uccessfu|lly comp|
|00002c80| 69 6c 65 64 2c 20 61 6e | 20 61 74 74 65 6d 70 74 |iled, an| attempt|
|00002c90| 20 69 73 20 6d 61 64 65 | 20 74 6f 0d 77 72 69 74 | is made| to.writ|
|00002ca0| 65 20 74 68 65 20 63 6f | 6d 70 69 6c 65 64 20 76 |e the co|mpiled v|
|00002cb0| 65 72 73 69 6f 6e 20 74 | 6f 20 7b 5c 74 74 20 66 |ersion t|o {\tt f|
|00002cc0| 6f 6f 2e 70 79 63 7d 2e | 20 20 49 74 20 69 73 20 |oo.pyc}.| It is |
|00002cd0| 6e 6f 74 20 61 6e 20 65 | 72 72 6f 72 20 69 66 0d |not an e|rror if.|
|00002ce0| 74 68 69 73 20 61 74 74 | 65 6d 70 74 20 66 61 69 |this att|empt fai|
|00002cf0| 6c 73 3b 20 69 66 20 66 | 6f 72 20 61 6e 79 20 72 |ls; if f|or any r|
|00002d00| 65 61 73 6f 6e 20 74 68 | 65 20 66 69 6c 65 20 69 |eason th|e file i|
|00002d10| 73 20 6e 6f 74 20 77 72 | 69 74 74 65 6e 0d 63 6f |s not wr|itten.co|
|00002d20| 6d 70 6c 65 74 65 6c 79 | 2c 20 74 68 65 20 72 65 |mpletely|, the re|
|00002d30| 73 75 6c 74 69 6e 67 20 | 7b 5c 74 74 20 66 6f 6f |sulting |{\tt foo|
|00002d40| 2e 70 79 63 7d 20 66 69 | 6c 65 20 77 69 6c 6c 20 |.pyc} fi|le will |
|00002d50| 62 65 20 72 65 63 6f 67 | 6e 69 7a 65 64 20 61 73 |be recog|nized as|
|00002d60| 0d 69 6e 76 61 6c 69 64 | 20 61 6e 64 20 74 68 75 |.invalid| and thu|
|00002d70| 73 20 69 67 6e 6f 72 65 | 64 20 6c 61 74 65 72 2e |s ignore|d later.|
|00002d80| 0d 0d 5c 73 75 62 73 65 | 63 74 69 6f 6e 7b 45 78 |..\subse|ction{Ex|
|00002d90| 65 63 75 74 61 62 6c 65 | 20 50 79 74 68 6f 6e 20 |ecutable| Python |
|00002da0| 73 63 72 69 70 74 73 7d | 0d 0d 4f 6e 20 42 53 44 |scripts}|..On BSD|
|00002db0| 27 69 73 68 20 7b 5c 55 | 4e 49 58 7d 20 73 79 73 |'ish {\U|NIX} sys|
|00002dc0| 74 65 6d 73 2c 20 50 79 | 74 68 6f 6e 20 73 63 72 |tems, Py|thon scr|
|00002dd0| 69 70 74 73 20 63 61 6e | 20 62 65 20 6d 61 64 65 |ipts can| be made|
|00002de0| 20 64 69 72 65 63 74 6c | 79 0d 65 78 65 63 75 74 | directl|y.execut|
|00002df0| 61 62 6c 65 2c 20 6c 69 | 6b 65 20 73 68 65 6c 6c |able, li|ke shell|
|00002e00| 20 73 63 72 69 70 74 73 | 2c 20 62 79 20 70 75 74 | scripts|, by put|
|00002e10| 74 69 6e 67 20 74 68 65 | 20 6c 69 6e 65 0d 0d 5c |ting the| line..\|
|00002e20| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|00002e30| 61 74 69 6d 7d 0d 23 21 | 20 2f 75 73 72 2f 6c 6f |atim}.#!| /usr/lo|
|00002e40| 63 61 6c 2f 62 69 6e 2f | 70 79 74 68 6f 6e 0d 5c |cal/bin/|python.\|
|00002e50| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 5c 65 63 |end{verb|atim}\ec|
|00002e60| 6f 64 65 0d 25 0d 28 61 | 73 73 75 6d 69 6e 67 20 |ode.%.(a|ssuming |
|00002e70| 74 68 61 74 27 73 20 74 | 68 65 20 6e 61 6d 65 20 |that's t|he name |
|00002e80| 6f 66 20 74 68 65 20 69 | 6e 74 65 72 70 72 65 74 |of the i|nterpret|
|00002e90| 65 72 29 20 61 74 20 74 | 68 65 20 62 65 67 69 6e |er) at t|he begin|
|00002ea0| 6e 69 6e 67 20 6f 66 20 | 74 68 65 0d 73 63 72 69 |ning of |the.scri|
|00002eb0| 70 74 20 61 6e 64 20 67 | 69 76 69 6e 67 20 74 68 |pt and g|iving th|
|00002ec0| 65 20 66 69 6c 65 20 61 | 6e 20 65 78 65 63 75 74 |e file a|n execut|
|00002ed0| 61 62 6c 65 20 6d 6f 64 | 65 2e 20 20 54 68 65 20 |able mod|e. The |
|00002ee0| 7b 5c 74 74 20 5c 23 21 | 7d 20 6d 75 73 74 20 62 |{\tt \#!|} must b|
|00002ef0| 65 0d 74 68 65 20 66 69 | 72 73 74 20 74 77 6f 20 |e.the fi|rst two |
|00002f00| 63 68 61 72 61 63 74 65 | 72 73 20 6f 66 20 74 68 |characte|rs of th|
|00002f10| 65 20 66 69 6c 65 2e 0d | 0d 5c 73 75 62 73 65 63 |e file..|.\subsec|
|00002f20| 74 69 6f 6e 7b 54 68 65 | 20 49 6e 74 65 72 61 63 |tion{The| Interac|
|00002f30| 74 69 76 65 20 53 74 61 | 72 74 75 70 20 46 69 6c |tive Sta|rtup Fil|
|00002f40| 65 7d 0d 0d 57 68 65 6e | 20 79 6f 75 20 75 73 65 |e}..When| you use|
|00002f50| 20 50 79 74 68 6f 6e 20 | 69 6e 74 65 72 61 63 74 | Python |interact|
|00002f60| 69 76 65 6c 79 2c 20 69 | 74 20 69 73 20 66 72 65 |ively, i|t is fre|
|00002f70| 71 75 65 6e 74 6c 79 20 | 68 61 6e 64 79 20 74 6f |quently |handy to|
|00002f80| 20 68 61 76 65 20 73 6f | 6d 65 0d 73 74 61 6e 64 | have so|me.stand|
|00002f90| 61 72 64 20 63 6f 6d 6d | 61 6e 64 73 20 65 78 65 |ard comm|ands exe|
|00002fa0| 63 75 74 65 64 20 65 76 | 65 72 79 20 74 69 6d 65 |cuted ev|ery time|
|00002fb0| 20 74 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 | the int|erpreter|
|00002fc0| 20 69 73 20 73 74 61 72 | 74 65 64 2e 20 20 59 6f | is star|ted. Yo|
|00002fd0| 75 0d 63 61 6e 20 64 6f | 20 74 68 69 73 20 62 79 |u.can do| this by|
|00002fe0| 20 73 65 74 74 69 6e 67 | 20 61 6e 20 65 6e 76 69 | setting| an envi|
|00002ff0| 72 6f 6e 6d 65 6e 74 20 | 76 61 72 69 61 62 6c 65 |ronment |variable|
|00003000| 20 6e 61 6d 65 64 20 7b | 5c 74 74 0d 50 59 54 48 | named {|\tt.PYTH|
|00003010| 4f 4e 53 54 41 52 54 55 | 50 7d 20 74 6f 20 74 68 |ONSTARTU|P} to th|
|00003020| 65 20 6e 61 6d 65 20 6f | 66 20 61 20 66 69 6c 65 |e name o|f a file|
|00003030| 20 63 6f 6e 74 61 69 6e | 69 6e 67 20 79 6f 75 72 | contain|ing your|
|00003040| 20 73 74 61 72 74 2d 75 | 70 0d 63 6f 6d 6d 61 6e | start-u|p.comman|
|00003050| 64 73 2e 20 20 54 68 69 | 73 20 69 73 20 73 69 6d |ds. Thi|s is sim|
|00003060| 69 6c 61 72 20 74 6f 20 | 74 68 65 20 7b 5c 74 74 |ilar to |the {\tt|
|00003070| 20 2e 70 72 6f 66 69 6c | 65 7d 20 66 65 61 74 75 | .profil|e} featu|
|00003080| 72 65 20 6f 66 20 74 68 | 65 20 55 4e 49 58 0d 73 |re of th|e UNIX.s|
|00003090| 68 65 6c 6c 73 2e 0d 0d | 54 68 69 73 20 66 69 6c |hells...|This fil|
|000030a0| 65 20 69 73 20 6f 6e 6c | 79 20 72 65 61 64 20 69 |e is onl|y read i|
|000030b0| 6e 20 69 6e 74 65 72 61 | 63 74 69 76 65 20 73 65 |n intera|ctive se|
|000030c0| 73 73 69 6f 6e 73 2c 20 | 6e 6f 74 20 77 68 65 6e |ssions, |not when|
|000030d0| 20 50 79 74 68 6f 6e 20 | 72 65 61 64 73 0d 63 6f | Python |reads.co|
|000030e0| 6d 6d 61 6e 64 73 20 66 | 72 6f 6d 20 61 20 73 63 |mmands f|rom a sc|
|000030f0| 72 69 70 74 2c 20 61 6e | 64 20 6e 6f 74 20 77 68 |ript, an|d not wh|
|00003100| 65 6e 20 7b 5c 74 74 20 | 2f 64 65 76 2f 74 74 79 |en {\tt |/dev/tty|
|00003110| 7d 20 69 73 20 67 69 76 | 65 6e 20 61 73 20 74 68 |} is giv|en as th|
|00003120| 65 0d 65 78 70 6c 69 63 | 69 74 20 73 6f 75 72 63 |e.explic|it sourc|
|00003130| 65 20 6f 66 20 63 6f 6d | 6d 61 6e 64 73 20 28 77 |e of com|mands (w|
|00003140| 68 69 63 68 20 6f 74 68 | 65 72 77 69 73 65 20 62 |hich oth|erwise b|
|00003150| 65 68 61 76 65 73 20 6c | 69 6b 65 20 61 6e 0d 69 |ehaves l|ike an.i|
|00003160| 6e 74 65 72 61 63 74 69 | 76 65 20 73 65 73 73 69 |nteracti|ve sessi|
|00003170| 6f 6e 29 2e 20 20 49 74 | 20 69 73 20 65 78 65 63 |on). It| is exec|
|00003180| 75 74 65 64 20 69 6e 20 | 74 68 65 20 73 61 6d 65 |uted in |the same|
|00003190| 20 6e 61 6d 65 20 73 70 | 61 63 65 20 77 68 65 72 | name sp|ace wher|
|000031a0| 65 0d 69 6e 74 65 72 61 | 63 74 69 76 65 20 63 6f |e.intera|ctive co|
|000031b0| 6d 6d 61 6e 64 73 20 61 | 72 65 20 65 78 65 63 75 |mmands a|re execu|
|000031c0| 74 65 64 2c 20 73 6f 20 | 74 68 61 74 20 6f 62 6a |ted, so |that obj|
|000031d0| 65 63 74 73 20 74 68 61 | 74 20 69 74 20 64 65 66 |ects tha|t it def|
|000031e0| 69 6e 65 73 20 6f 72 0d | 69 6d 70 6f 72 74 73 20 |ines or.|imports |
|000031f0| 63 61 6e 20 62 65 20 75 | 73 65 64 20 77 69 74 68 |can be u|sed with|
|00003200| 6f 75 74 20 71 75 61 6c | 69 66 69 63 61 74 69 6f |out qual|ificatio|
|00003210| 6e 20 69 6e 20 74 68 65 | 20 69 6e 74 65 72 61 63 |n in the| interac|
|00003220| 74 69 76 65 20 73 65 73 | 73 69 6f 6e 2e 0d 59 6f |tive ses|sion..Yo|
|00003230| 75 20 63 61 6e 20 61 6c | 73 6f 20 63 68 61 6e 67 |u can al|so chang|
|00003240| 65 20 74 68 65 20 70 72 | 6f 6d 70 74 73 20 7b 5c |e the pr|ompts {\|
|00003250| 74 74 20 73 79 73 2e 70 | 73 31 7d 20 61 6e 64 20 |tt sys.p|s1} and |
|00003260| 7b 5c 74 74 20 73 79 73 | 2e 70 73 32 7d 20 69 6e |{\tt sys|.ps2} in|
|00003270| 0d 74 68 69 73 20 66 69 | 6c 65 2e 0d 0d 49 66 20 |.this fi|le...If |
|00003280| 79 6f 75 20 77 61 6e 74 | 20 74 6f 20 72 65 61 64 |you want| to read|
|00003290| 20 61 6e 20 61 64 64 69 | 74 69 6f 6e 61 6c 20 73 | an addi|tional s|
|000032a0| 74 61 72 74 2d 75 70 20 | 66 69 6c 65 20 66 72 6f |tart-up |file fro|
|000032b0| 6d 20 74 68 65 20 63 75 | 72 72 65 6e 74 0d 64 69 |m the cu|rrent.di|
|000032c0| 72 65 63 74 6f 72 79 2c | 20 79 6f 75 20 63 61 6e |rectory,| you can|
|000032d0| 20 70 72 6f 67 72 61 6d | 20 74 68 69 73 20 69 6e | program| this in|
|000032e0| 20 74 68 65 20 67 6c 6f | 62 61 6c 20 73 74 61 72 | the glo|bal star|
|000032f0| 74 2d 75 70 20 66 69 6c | 65 2c 20 65 2e 67 2e 0d |t-up fil|e, e.g..|
|00003300| 5c 76 65 72 62 5c 65 78 | 65 63 66 69 6c 65 28 27 |\verb\ex|ecfile('|
|00003310| 2e 70 79 74 68 6f 6e 72 | 63 27 29 5c 2e 20 20 49 |.pythonr|c')\. I|
|00003320| 66 20 79 6f 75 20 77 61 | 6e 74 20 74 6f 20 75 73 |f you wa|nt to us|
|00003330| 65 20 74 68 65 20 73 74 | 61 72 74 75 70 20 66 69 |e the st|artup fi|
|00003340| 6c 65 0d 69 6e 20 61 20 | 73 63 72 69 70 74 2c 20 |le.in a |script, |
|00003350| 79 6f 75 20 6d 75 73 74 | 20 77 72 69 74 65 20 74 |you must| write t|
|00003360| 68 69 73 20 65 78 70 6c | 69 63 69 74 6c 79 20 69 |his expl|icitly i|
|00003370| 6e 20 74 68 65 20 73 63 | 72 69 70 74 2c 20 65 2e |n the sc|ript, e.|
|00003380| 67 2e 0d 5c 76 65 72 62 | 5c 69 6d 70 6f 72 74 20 |g..\verb|\import |
|00003390| 6f 73 3b 5c 20 5c 76 65 | 72 62 5c 65 78 65 63 66 |os;\ \ve|rb\execf|
|000033a0| 69 6c 65 28 6f 73 2e 65 | 6e 76 69 72 6f 6e 5b 27 |ile(os.e|nviron['|
|000033b0| 50 59 54 48 4f 4e 53 54 | 41 52 54 55 50 27 5d 29 |PYTHONST|ARTUP'])|
|000033c0| 5c 2e 0d 0d 5c 73 65 63 | 74 69 6f 6e 7b 49 6e 74 |\...\sec|tion{Int|
|000033d0| 65 72 61 63 74 69 76 65 | 20 49 6e 70 75 74 20 45 |eractive| Input E|
|000033e0| 64 69 74 69 6e 67 20 61 | 6e 64 20 48 69 73 74 6f |diting a|nd Histo|
|000033f0| 72 79 20 53 75 62 73 74 | 69 74 75 74 69 6f 6e 7d |ry Subst|itution}|
|00003400| 0d 0d 53 6f 6d 65 20 76 | 65 72 73 69 6f 6e 73 20 |..Some v|ersions |
|00003410| 6f 66 20 74 68 65 20 50 | 79 74 68 6f 6e 20 69 6e |of the P|ython in|
|00003420| 74 65 72 70 72 65 74 65 | 72 20 73 75 70 70 6f 72 |terprete|r suppor|
|00003430| 74 20 65 64 69 74 69 6e | 67 20 6f 66 20 74 68 65 |t editin|g of the|
|00003440| 20 63 75 72 72 65 6e 74 | 0d 69 6e 70 75 74 20 6c | current|.input l|
|00003450| 69 6e 65 20 61 6e 64 20 | 68 69 73 74 6f 72 79 20 |ine and |history |
|00003460| 73 75 62 73 74 69 74 75 | 74 69 6f 6e 2c 20 73 69 |substitu|tion, si|
|00003470| 6d 69 6c 61 72 20 74 6f | 20 66 61 63 69 6c 69 74 |milar to| facilit|
|00003480| 69 65 73 20 66 6f 75 6e | 64 20 69 6e 0d 74 68 65 |ies foun|d in.the|
|00003490| 20 4b 6f 72 6e 20 73 68 | 65 6c 6c 20 61 6e 64 20 | Korn sh|ell and |
|000034a0| 74 68 65 20 47 4e 55 20 | 42 61 73 68 20 73 68 65 |the GNU |Bash she|
|000034b0| 6c 6c 2e 20 20 54 68 69 | 73 20 69 73 20 69 6d 70 |ll. Thi|s is imp|
|000034c0| 6c 65 6d 65 6e 74 65 64 | 20 75 73 69 6e 67 20 74 |lemented| using t|
|000034d0| 68 65 0d 7b 5c 65 6d 20 | 47 4e 55 5c 20 52 65 61 |he.{\em |GNU\ Rea|
|000034e0| 64 6c 69 6e 65 7d 20 6c | 69 62 72 61 72 79 2c 20 |dline} l|ibrary, |
|000034f0| 77 68 69 63 68 20 73 75 | 70 70 6f 72 74 73 20 45 |which su|pports E|
|00003500| 6d 61 63 73 2d 73 74 79 | 6c 65 20 61 6e 64 20 76 |macs-sty|le and v|
|00003510| 69 2d 73 74 79 6c 65 0d | 65 64 69 74 69 6e 67 2e |i-style.|editing.|
|00003520| 20 20 54 68 69 73 20 6c | 69 62 72 61 72 79 20 68 | This l|ibrary h|
|00003530| 61 73 20 69 74 73 20 6f | 77 6e 20 64 6f 63 75 6d |as its o|wn docum|
|00003540| 65 6e 74 61 74 69 6f 6e | 20 77 68 69 63 68 20 49 |entation| which I|
|00003550| 20 77 6f 6e 27 74 0d 64 | 75 70 6c 69 63 61 74 65 | won't.d|uplicate|
|00003560| 20 68 65 72 65 3b 20 68 | 6f 77 65 76 65 72 2c 20 | here; h|owever, |
|00003570| 74 68 65 20 62 61 73 69 | 63 73 20 61 72 65 20 65 |the basi|cs are e|
|00003580| 61 73 69 6c 79 20 65 78 | 70 6c 61 69 6e 65 64 2e |asily ex|plained.|
|00003590| 0d 0d 50 65 72 68 61 70 | 73 20 74 68 65 20 71 75 |..Perhap|s the qu|
|000035a0| 69 63 6b 65 73 74 20 63 | 68 65 63 6b 20 74 6f 20 |ickest c|heck to |
|000035b0| 73 65 65 20 77 68 65 74 | 68 65 72 20 63 6f 6d 6d |see whet|her comm|
|000035c0| 61 6e 64 20 6c 69 6e 65 | 20 65 64 69 74 69 6e 67 |and line| editing|
|000035d0| 20 69 73 0d 73 75 70 70 | 6f 72 74 65 64 20 69 73 | is.supp|orted is|
|000035e0| 20 74 79 70 69 6e 67 20 | 43 6f 6e 74 72 6f 6c 2d | typing |Control-|
|000035f0| 50 20 74 6f 20 74 68 65 | 20 66 69 72 73 74 20 50 |P to the| first P|
|00003600| 79 74 68 6f 6e 20 70 72 | 6f 6d 70 74 20 79 6f 75 |ython pr|ompt you|
|00003610| 20 67 65 74 2e 20 20 49 | 66 0d 69 74 20 62 65 65 | get. I|f.it bee|
|00003620| 70 73 2c 20 79 6f 75 20 | 68 61 76 65 20 63 6f 6d |ps, you |have com|
|00003630| 6d 61 6e 64 20 6c 69 6e | 65 20 65 64 69 74 69 6e |mand lin|e editin|
|00003640| 67 2e 20 20 49 66 20 6e | 6f 74 68 69 6e 67 20 61 |g. If n|othing a|
|00003650| 70 70 65 61 72 73 20 74 | 6f 0d 68 61 70 70 65 6e |ppears t|o.happen|
|00003660| 2c 20 6f 72 20 69 66 20 | 5c 76 65 72 62 2f 5e 50 |, or if |\verb/^P|
|00003670| 2f 20 69 73 20 65 63 68 | 6f 65 64 2c 20 79 6f 75 |/ is ech|oed, you|
|00003680| 20 63 61 6e 20 73 6b 69 | 70 20 74 68 65 20 72 65 | can ski|p the re|
|00003690| 73 74 20 6f 66 20 74 68 | 69 73 0d 73 65 63 74 69 |st of th|is.secti|
|000036a0| 6f 6e 2e 0d 0d 5c 73 75 | 62 73 65 63 74 69 6f 6e |on...\su|bsection|
|000036b0| 7b 4c 69 6e 65 20 45 64 | 69 74 69 6e 67 7d 0d 0d |{Line Ed|iting}..|
|000036c0| 49 66 20 73 75 70 70 6f | 72 74 65 64 2c 20 69 6e |If suppo|rted, in|
|000036d0| 70 75 74 20 6c 69 6e 65 | 20 65 64 69 74 69 6e 67 |put line| editing|
|000036e0| 20 69 73 20 61 63 74 69 | 76 65 20 77 68 65 6e 65 | is acti|ve whene|
|000036f0| 76 65 72 20 74 68 65 20 | 69 6e 74 65 72 70 72 65 |ver the |interpre|
|00003700| 74 65 72 0d 70 72 69 6e | 74 73 20 61 20 70 72 69 |ter.prin|ts a pri|
|00003710| 6d 61 72 79 20 6f 72 20 | 73 65 63 6f 6e 64 61 72 |mary or |secondar|
|00003720| 79 20 70 72 6f 6d 70 74 | 2e 20 20 54 68 65 20 63 |y prompt|. The c|
|00003730| 75 72 72 65 6e 74 20 6c | 69 6e 65 20 63 61 6e 20 |urrent l|ine can |
|00003740| 62 65 20 65 64 69 74 65 | 64 0d 75 73 69 6e 67 20 |be edite|d.using |
|00003750| 74 68 65 20 63 6f 6e 76 | 65 6e 74 69 6f 6e 61 6c |the conv|entional|
|00003760| 20 45 6d 61 63 73 20 63 | 6f 6e 74 72 6f 6c 20 63 | Emacs c|ontrol c|
|00003770| 68 61 72 61 63 74 65 72 | 73 2e 20 20 54 68 65 20 |haracter|s. The |
|00003780| 6d 6f 73 74 20 69 6d 70 | 6f 72 74 61 6e 74 0d 6f |most imp|ortant.o|
|00003790| 66 20 74 68 65 73 65 20 | 61 72 65 3a 20 43 2d 41 |f these |are: C-A|
|000037a0| 20 28 43 6f 6e 74 72 6f | 6c 2d 41 29 20 6d 6f 76 | (Contro|l-A) mov|
|000037b0| 65 73 20 74 68 65 20 63 | 75 72 73 6f 72 20 74 6f |es the c|ursor to|
|000037c0| 20 74 68 65 20 62 65 67 | 69 6e 6e 69 6e 67 20 6f | the beg|inning o|
|000037d0| 66 20 74 68 65 0d 6c 69 | 6e 65 2c 20 43 2d 45 20 |f the.li|ne, C-E |
|000037e0| 74 6f 20 74 68 65 20 65 | 6e 64 2c 20 43 2d 42 20 |to the e|nd, C-B |
|000037f0| 6d 6f 76 65 73 20 69 74 | 20 6f 6e 65 20 70 6f 73 |moves it| one pos|
|00003800| 69 74 69 6f 6e 20 74 6f | 20 74 68 65 20 6c 65 66 |ition to| the lef|
|00003810| 74 2c 20 43 2d 46 20 74 | 6f 0d 74 68 65 20 72 69 |t, C-F t|o.the ri|
|00003820| 67 68 74 2e 20 20 42 61 | 63 6b 73 70 61 63 65 20 |ght. Ba|ckspace |
|00003830| 65 72 61 73 65 73 20 74 | 68 65 20 63 68 61 72 61 |erases t|he chara|
|00003840| 63 74 65 72 20 74 6f 20 | 74 68 65 20 6c 65 66 74 |cter to |the left|
|00003850| 20 6f 66 20 74 68 65 20 | 63 75 72 73 6f 72 2c 0d | of the |cursor,.|
|00003860| 43 2d 44 20 74 68 65 20 | 63 68 61 72 61 63 74 65 |C-D the |characte|
|00003870| 72 20 74 6f 20 69 74 73 | 20 72 69 67 68 74 2e 20 |r to its| right. |
|00003880| 20 43 2d 4b 20 6b 69 6c | 6c 73 20 28 65 72 61 73 | C-K kil|ls (eras|
|00003890| 65 73 29 20 74 68 65 20 | 72 65 73 74 20 6f 66 20 |es) the |rest of |
|000038a0| 74 68 65 0d 6c 69 6e 65 | 20 74 6f 20 74 68 65 20 |the.line| to the |
|000038b0| 72 69 67 68 74 20 6f 66 | 20 74 68 65 20 63 75 72 |right of| the cur|
|000038c0| 73 6f 72 2c 20 43 2d 59 | 20 79 61 6e 6b 73 20 62 |sor, C-Y| yanks b|
|000038d0| 61 63 6b 20 74 68 65 20 | 6c 61 73 74 20 6b 69 6c |ack the |last kil|
|000038e0| 6c 65 64 0d 73 74 72 69 | 6e 67 2e 20 20 43 2d 75 |led.stri|ng. C-u|
|000038f0| 6e 64 65 72 73 63 6f 72 | 65 20 75 6e 64 6f 65 73 |nderscor|e undoes|
|00003900| 20 74 68 65 20 6c 61 73 | 74 20 63 68 61 6e 67 65 | the las|t change|
|00003910| 20 79 6f 75 20 6d 61 64 | 65 3b 20 69 74 20 63 61 | you mad|e; it ca|
|00003920| 6e 20 62 65 0d 72 65 70 | 65 61 74 65 64 20 66 6f |n be.rep|eated fo|
|00003930| 72 20 63 75 6d 75 6c 61 | 74 69 76 65 20 65 66 66 |r cumula|tive eff|
|00003940| 65 63 74 2e 0d 0d 5c 73 | 75 62 73 65 63 74 69 6f |ect...\s|ubsectio|
|00003950| 6e 7b 48 69 73 74 6f 72 | 79 20 53 75 62 73 74 69 |n{Histor|y Substi|
|00003960| 74 75 74 69 6f 6e 7d 0d | 0d 48 69 73 74 6f 72 79 |tution}.|.History|
|00003970| 20 73 75 62 73 74 69 74 | 75 74 69 6f 6e 20 77 6f | substit|ution wo|
|00003980| 72 6b 73 20 61 73 20 66 | 6f 6c 6c 6f 77 73 2e 20 |rks as f|ollows. |
|00003990| 20 41 6c 6c 20 6e 6f 6e | 2d 65 6d 70 74 79 20 69 | All non|-empty i|
|000039a0| 6e 70 75 74 20 6c 69 6e | 65 73 0d 69 73 73 75 65 |nput lin|es.issue|
|000039b0| 64 20 61 72 65 20 73 61 | 76 65 64 20 69 6e 20 61 |d are sa|ved in a|
|000039c0| 20 68 69 73 74 6f 72 79 | 20 62 75 66 66 65 72 2c | history| buffer,|
|000039d0| 20 61 6e 64 20 77 68 65 | 6e 20 61 20 6e 65 77 20 | and whe|n a new |
|000039e0| 70 72 6f 6d 70 74 20 69 | 73 20 67 69 76 65 6e 0d |prompt i|s given.|
|000039f0| 79 6f 75 20 61 72 65 20 | 70 6f 73 69 74 69 6f 6e |you are |position|
|00003a00| 65 64 20 6f 6e 20 61 20 | 6e 65 77 20 6c 69 6e 65 |ed on a |new line|
|00003a10| 20 61 74 20 74 68 65 20 | 62 6f 74 74 6f 6d 20 6f | at the |bottom o|
|00003a20| 66 20 74 68 69 73 20 62 | 75 66 66 65 72 2e 20 20 |f this b|uffer. |
|00003a30| 43 2d 50 0d 6d 6f 76 65 | 73 20 6f 6e 65 20 6c 69 |C-P.move|s one li|
|00003a40| 6e 65 20 75 70 20 28 62 | 61 63 6b 29 20 69 6e 20 |ne up (b|ack) in |
|00003a50| 74 68 65 20 68 69 73 74 | 6f 72 79 20 62 75 66 66 |the hist|ory buff|
|00003a60| 65 72 2c 20 43 2d 4e 20 | 6d 6f 76 65 73 20 6f 6e |er, C-N |moves on|
|00003a70| 65 20 64 6f 77 6e 2e 0d | 41 6e 79 20 6c 69 6e 65 |e down..|Any line|
|00003a80| 20 69 6e 20 74 68 65 20 | 68 69 73 74 6f 72 79 20 | in the |history |
|00003a90| 62 75 66 66 65 72 20 63 | 61 6e 20 62 65 20 65 64 |buffer c|an be ed|
|00003aa0| 69 74 65 64 3b 20 61 6e | 20 61 73 74 65 72 69 73 |ited; an| asteris|
|00003ab0| 6b 20 61 70 70 65 61 72 | 73 20 69 6e 0d 66 72 6f |k appear|s in.fro|
|00003ac0| 6e 74 20 6f 66 20 74 68 | 65 20 70 72 6f 6d 70 74 |nt of th|e prompt|
|00003ad0| 20 74 6f 20 6d 61 72 6b | 20 61 20 6c 69 6e 65 20 | to mark| a line |
|00003ae0| 61 73 20 6d 6f 64 69 66 | 69 65 64 2e 20 20 50 72 |as modif|ied. Pr|
|00003af0| 65 73 73 69 6e 67 20 74 | 68 65 20 52 65 74 75 72 |essing t|he Retur|
|00003b00| 6e 0d 6b 65 79 20 70 61 | 73 73 65 73 20 74 68 65 |n.key pa|sses the|
|00003b10| 20 63 75 72 72 65 6e 74 | 20 6c 69 6e 65 20 74 6f | current| line to|
|00003b20| 20 74 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 | the int|erpreter|
|00003b30| 2e 20 20 43 2d 52 20 73 | 74 61 72 74 73 20 61 6e |. C-R s|tarts an|
|00003b40| 0d 69 6e 63 72 65 6d 65 | 6e 74 61 6c 20 72 65 76 |.increme|ntal rev|
|00003b50| 65 72 73 65 20 73 65 61 | 72 63 68 3b 20 43 2d 53 |erse sea|rch; C-S|
|00003b60| 20 73 74 61 72 74 73 20 | 61 20 66 6f 72 77 61 72 | starts |a forwar|
|00003b70| 64 20 73 65 61 72 63 68 | 2e 0d 0d 5c 73 75 62 73 |d search|...\subs|
|00003b80| 65 63 74 69 6f 6e 7b 4b | 65 79 20 42 69 6e 64 69 |ection{K|ey Bindi|
|00003b90| 6e 67 73 7d 0d 0d 54 68 | 65 20 6b 65 79 20 62 69 |ngs}..Th|e key bi|
|00003ba0| 6e 64 69 6e 67 73 20 61 | 6e 64 20 73 6f 6d 65 20 |ndings a|nd some |
|00003bb0| 6f 74 68 65 72 20 70 61 | 72 61 6d 65 74 65 72 73 |other pa|rameters|
|00003bc0| 20 6f 66 20 74 68 65 20 | 52 65 61 64 6c 69 6e 65 | of the |Readline|
|00003bd0| 20 6c 69 62 72 61 72 79 | 20 63 61 6e 0d 62 65 20 | library| can.be |
|00003be0| 63 75 73 74 6f 6d 69 7a | 65 64 20 62 79 20 70 6c |customiz|ed by pl|
|00003bf0| 61 63 69 6e 67 20 63 6f | 6d 6d 61 6e 64 73 20 69 |acing co|mmands i|
|00003c00| 6e 20 61 6e 20 69 6e 69 | 74 69 61 6c 69 7a 61 74 |n an ini|tializat|
|00003c10| 69 6f 6e 20 66 69 6c 65 | 20 63 61 6c 6c 65 64 0d |ion file| called.|
|00003c20| 7b 5c 74 74 20 5c 24 48 | 4f 4d 45 2f 2e 69 6e 70 |{\tt \$H|OME/.inp|
|00003c30| 75 74 72 63 7d 2e 20 20 | 4b 65 79 20 62 69 6e 64 |utrc}. |Key bind|
|00003c40| 69 6e 67 73 20 68 61 76 | 65 20 74 68 65 20 66 6f |ings hav|e the fo|
|00003c50| 72 6d 0d 0d 5c 62 63 6f | 64 65 5c 62 65 67 69 6e |rm..\bco|de\begin|
|00003c60| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 6b 65 79 2d 6e |{verbati|m}.key-n|
|00003c70| 61 6d 65 3a 20 66 75 6e | 63 74 69 6f 6e 2d 6e 61 |ame: fun|ction-na|
|00003c80| 6d 65 0d 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |me.\end{|verbatim|
|00003c90| 7d 5c 65 63 6f 64 65 0d | 25 0d 6f 72 0d 0d 5c 62 |}\ecode.|%.or..\b|
|00003ca0| 63 6f 64 65 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |code\beg|in{verba|
|00003cb0| 74 69 6d 7d 0d 22 73 74 | 72 69 6e 67 22 3a 20 66 |tim}."st|ring": f|
|00003cc0| 75 6e 63 74 69 6f 6e 2d | 6e 61 6d 65 0d 5c 65 6e |unction-|name.\en|
|00003cd0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00003ce0| 65 0d 25 0d 61 6e 64 20 | 6f 70 74 69 6f 6e 73 20 |e.%.and |options |
|00003cf0| 63 61 6e 20 62 65 20 73 | 65 74 20 77 69 74 68 0d |can be s|et with.|
|00003d00| 0d 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|00003d10| 72 62 61 74 69 6d 7d 0d | 73 65 74 20 6f 70 74 69 |rbatim}.|set opti|
|00003d20| 6f 6e 2d 6e 61 6d 65 20 | 76 61 6c 75 65 0d 5c 65 |on-name |value.\e|
|00003d30| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 5c 65 63 6f |nd{verba|tim}\eco|
|00003d40| 64 65 0d 25 0d 46 6f 72 | 20 65 78 61 6d 70 6c 65 |de.%.For| example|
|00003d50| 3a 0d 0d 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |:..\bcod|e\begin{|
|00003d60| 76 65 72 62 61 74 69 6d | 7d 0d 23 20 49 20 70 72 |verbatim|}.# I pr|
|00003d70| 65 66 65 72 20 76 69 2d | 73 74 79 6c 65 20 65 64 |efer vi-|style ed|
|00003d80| 69 74 69 6e 67 3a 0d 73 | 65 74 20 65 64 69 74 69 |iting:.s|et editi|
|00003d90| 6e 67 2d 6d 6f 64 65 20 | 76 69 0d 23 20 45 64 69 |ng-mode |vi.# Edi|
|00003da0| 74 20 75 73 69 6e 67 20 | 61 20 73 69 6e 67 6c 65 |t using |a single|
|00003db0| 20 6c 69 6e 65 3a 0d 73 | 65 74 20 68 6f 72 69 7a | line:.s|et horiz|
|00003dc0| 6f 6e 74 61 6c 2d 73 63 | 72 6f 6c 6c 2d 6d 6f 64 |ontal-sc|roll-mod|
|00003dd0| 65 20 4f 6e 0d 23 20 52 | 65 62 69 6e 64 20 73 6f |e On.# R|ebind so|
|00003de0| 6d 65 20 6b 65 79 73 3a | 0d 4d 65 74 61 2d 68 3a |me keys:|.Meta-h:|
|00003df0| 20 62 61 63 6b 77 61 72 | 64 2d 6b 69 6c 6c 2d 77 | backwar|d-kill-w|
|00003e00| 6f 72 64 0d 22 5c 43 2d | 75 22 3a 20 75 6e 69 76 |ord."\C-|u": univ|
|00003e10| 65 72 73 61 6c 2d 61 72 | 67 75 6d 65 6e 74 0d 22 |ersal-ar|gument."|
|00003e20| 5c 43 2d 78 5c 43 2d 72 | 22 3a 20 72 65 2d 72 65 |\C-x\C-r|": re-re|
|00003e30| 61 64 2d 69 6e 69 74 2d | 66 69 6c 65 0d 5c 65 6e |ad-init-|file.\en|
|00003e40| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00003e50| 65 0d 25 0d 4e 6f 74 65 | 20 74 68 61 74 20 74 68 |e.%.Note| that th|
|00003e60| 65 20 64 65 66 61 75 6c | 74 20 62 69 6e 64 69 6e |e defaul|t bindin|
|00003e70| 67 20 66 6f 72 20 54 41 | 42 20 69 6e 20 50 79 74 |g for TA|B in Pyt|
|00003e80| 68 6f 6e 20 69 73 20 74 | 6f 20 69 6e 73 65 72 74 |hon is t|o insert|
|00003e90| 20 61 20 54 41 42 0d 69 | 6e 73 74 65 61 64 20 6f | a TAB.i|nstead o|
|00003ea0| 66 20 52 65 61 64 6c 69 | 6e 65 27 73 20 64 65 66 |f Readli|ne's def|
|00003eb0| 61 75 6c 74 20 66 69 6c | 65 6e 61 6d 65 20 63 6f |ault fil|ename co|
|00003ec0| 6d 70 6c 65 74 69 6f 6e | 20 66 75 6e 63 74 69 6f |mpletion| functio|
|00003ed0| 6e 2e 20 20 49 66 20 79 | 6f 75 0d 69 6e 73 69 73 |n. If y|ou.insis|
|00003ee0| 74 2c 20 79 6f 75 20 63 | 61 6e 20 6f 76 65 72 72 |t, you c|an overr|
|00003ef0| 69 64 65 20 74 68 69 73 | 20 62 79 20 70 75 74 74 |ide this| by putt|
|00003f00| 69 6e 67 0d 0d 5c 62 63 | 6f 64 65 5c 62 65 67 69 |ing..\bc|ode\begi|
|00003f10| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0d 54 41 42 3a |n{verbat|im}.TAB:|
|00003f20| 20 63 6f 6d 70 6c 65 74 | 65 0d 5c 65 6e 64 7b 76 | complet|e.\end{v|
|00003f30| 65 72 62 61 74 69 6d 7d | 5c 65 63 6f 64 65 0d 25 |erbatim}|\ecode.%|
|00003f40| 0d 69 6e 20 79 6f 75 72 | 20 7b 5c 74 74 20 5c 24 |.in your| {\tt \$|
|00003f50| 48 4f 4d 45 2f 2e 69 6e | 70 75 74 72 63 7d 2e 20 |HOME/.in|putrc}. |
|00003f60| 20 28 4f 66 20 63 6f 75 | 72 73 65 2c 20 74 68 69 | (Of cou|rse, thi|
|00003f70| 73 20 6d 61 6b 65 73 20 | 69 74 20 68 61 72 64 20 |s makes |it hard |
|00003f80| 74 6f 20 74 79 70 65 0d | 69 6e 64 65 6e 74 65 64 |to type.|indented|
|00003f90| 20 63 6f 6e 74 69 6e 75 | 61 74 69 6f 6e 20 6c 69 | continu|ation li|
|00003fa0| 6e 65 73 2e 2e 2e 29 0d | 0d 5c 73 75 62 73 65 63 |nes...).|.\subsec|
|00003fb0| 74 69 6f 6e 7b 43 6f 6d | 6d 65 6e 74 61 72 79 7d |tion{Com|mentary}|
|00003fc0| 0d 0d 54 68 69 73 20 66 | 61 63 69 6c 69 74 79 20 |..This f|acility |
|00003fd0| 69 73 20 61 6e 20 65 6e | 6f 72 6d 6f 75 73 20 73 |is an en|ormous s|
|00003fe0| 74 65 70 20 66 6f 72 77 | 61 72 64 20 63 6f 6d 70 |tep forw|ard comp|
|00003ff0| 61 72 65 64 20 74 6f 20 | 70 72 65 76 69 6f 75 73 |ared to |previous|
|00004000| 0d 76 65 72 73 69 6f 6e | 73 20 6f 66 20 74 68 65 |.version|s of the|
|00004010| 20 69 6e 74 65 72 70 72 | 65 74 65 72 3b 20 68 6f | interpr|eter; ho|
|00004020| 77 65 76 65 72 2c 20 73 | 6f 6d 65 20 77 69 73 68 |wever, s|ome wish|
|00004030| 65 73 20 61 72 65 20 6c | 65 66 74 3a 20 49 74 20 |es are l|eft: It |
|00004040| 77 6f 75 6c 64 0d 62 65 | 20 6e 69 63 65 20 69 66 |would.be| nice if|
|00004050| 20 74 68 65 20 70 72 6f | 70 65 72 20 69 6e 64 65 | the pro|per inde|
|00004060| 6e 74 61 74 69 6f 6e 20 | 77 65 72 65 20 73 75 67 |ntation |were sug|
|00004070| 67 65 73 74 65 64 20 6f | 6e 20 63 6f 6e 74 69 6e |gested o|n contin|
|00004080| 75 61 74 69 6f 6e 20 6c | 69 6e 65 73 0d 28 74 68 |uation l|ines.(th|
|00004090| 65 20 70 61 72 73 65 72 | 20 6b 6e 6f 77 73 20 69 |e parser| knows i|
|000040a0| 66 20 61 6e 20 69 6e 64 | 65 6e 74 20 74 6f 6b 65 |f an ind|ent toke|
|000040b0| 6e 20 69 73 20 72 65 71 | 75 69 72 65 64 20 6e 65 |n is req|uired ne|
|000040c0| 78 74 29 2e 20 20 54 68 | 65 0d 63 6f 6d 70 6c 65 |xt). Th|e.comple|
|000040d0| 74 69 6f 6e 20 6d 65 63 | 68 61 6e 69 73 6d 20 6d |tion mec|hanism m|
|000040e0| 69 67 68 74 20 75 73 65 | 20 74 68 65 20 69 6e 74 |ight use| the int|
|000040f0| 65 72 70 72 65 74 65 72 | 27 73 20 73 79 6d 62 6f |erpreter|'s symbo|
|00004100| 6c 20 74 61 62 6c 65 2e | 20 20 41 0d 63 6f 6d 6d |l table.| A.comm|
|00004110| 61 6e 64 20 74 6f 20 63 | 68 65 63 6b 20 28 6f 72 |and to c|heck (or|
|00004120| 20 65 76 65 6e 20 73 75 | 67 67 65 73 74 29 20 6d | even su|ggest) m|
|00004130| 61 74 63 68 69 6e 67 20 | 70 61 72 65 6e 74 68 65 |atching |parenthe|
|00004140| 73 65 73 2c 20 71 75 6f | 74 65 73 20 65 74 63 2e |ses, quo|tes etc.|
|00004150| 0d 77 6f 75 6c 64 20 61 | 6c 73 6f 20 62 65 20 75 |.would a|lso be u|
|00004160| 73 65 66 75 6c 2e 0d 0d | 0d 5c 63 68 61 70 74 65 |seful...|.\chapte|
|00004170| 72 7b 41 6e 20 49 6e 66 | 6f 72 6d 61 6c 20 49 6e |r{An Inf|ormal In|
|00004180| 74 72 6f 64 75 63 74 69 | 6f 6e 20 74 6f 20 50 79 |troducti|on to Py|
|00004190| 74 68 6f 6e 7d 0d 0d 49 | 6e 20 74 68 65 20 66 6f |thon}..I|n the fo|
|000041a0| 6c 6c 6f 77 69 6e 67 20 | 65 78 61 6d 70 6c 65 73 |llowing |examples|
|000041b0| 2c 20 69 6e 70 75 74 20 | 61 6e 64 20 6f 75 74 70 |, input |and outp|
|000041c0| 75 74 20 61 72 65 20 64 | 69 73 74 69 6e 67 75 69 |ut are d|istingui|
|000041d0| 73 68 65 64 20 62 79 20 | 74 68 65 0d 70 72 65 73 |shed by |the.pres|
|000041e0| 65 6e 63 65 20 6f 72 20 | 61 62 73 65 6e 63 65 20 |ence or |absence |
|000041f0| 6f 66 20 70 72 6f 6d 70 | 74 73 20 28 7b 5c 74 74 |of promp|ts ({\tt|
|00004200| 20 3e 3e 3e 7d 20 61 6e | 64 20 7b 5c 74 74 20 2e | >>>} an|d {\tt .|
|00004210| 2e 2e 7d 29 3a 20 74 6f | 20 72 65 70 65 61 74 0d |..}): to| repeat.|
|00004220| 74 68 65 20 65 78 61 6d | 70 6c 65 2c 20 79 6f 75 |the exam|ple, you|
|00004230| 20 6d 75 73 74 20 74 79 | 70 65 20 65 76 65 72 79 | must ty|pe every|
|00004240| 74 68 69 6e 67 20 61 66 | 74 65 72 20 74 68 65 20 |thing af|ter the |
|00004250| 70 72 6f 6d 70 74 2c 20 | 77 68 65 6e 20 74 68 65 |prompt, |when the|
|00004260| 0d 70 72 6f 6d 70 74 20 | 61 70 70 65 61 72 73 3b |.prompt |appears;|
|00004270| 20 6c 69 6e 65 73 20 74 | 68 61 74 20 64 6f 20 6e | lines t|hat do n|
|00004280| 6f 74 20 62 65 67 69 6e | 20 77 69 74 68 20 61 20 |ot begin| with a |
|00004290| 70 72 6f 6d 70 74 20 61 | 72 65 20 6f 75 74 70 75 |prompt a|re outpu|
|000042a0| 74 20 66 72 6f 6d 0d 74 | 68 65 20 69 6e 74 65 72 |t from.t|he inter|
|000042b0| 70 72 65 74 65 72 2e 25 | 0d 5c 66 6f 6f 74 6e 6f |preter.%|.\footno|
|000042c0| 74 65 7b 0d 20 20 20 20 | 20 20 20 20 49 27 64 20 |te{. | I'd |
|000042d0| 70 72 65 66 65 72 20 74 | 6f 20 75 73 65 20 64 69 |prefer t|o use di|
|000042e0| 66 66 65 72 65 6e 74 20 | 66 6f 6e 74 73 20 74 6f |fferent |fonts to|
|000042f0| 20 64 69 73 74 69 6e 67 | 75 69 73 68 20 69 6e 70 | disting|uish inp|
|00004300| 75 74 0d 20 20 20 20 20 | 20 20 20 66 72 6f 6d 20 |ut. | from |
|00004310| 6f 75 74 70 75 74 2c 20 | 62 75 74 20 74 68 65 20 |output, |but the |
|00004320| 61 6d 6f 75 6e 74 20 6f | 66 20 4c 61 54 65 58 20 |amount o|f LaTeX |
|00004330| 68 61 63 6b 69 6e 67 20 | 74 68 61 74 20 77 6f 75 |hacking |that wou|
|00004340| 6c 64 20 72 65 71 75 69 | 72 65 0d 20 20 20 20 20 |ld requi|re. |
|00004350| 20 20 20 69 73 20 63 75 | 72 72 65 6e 74 6c 79 20 | is cu|rrently |
|00004360| 62 65 79 6f 6e 64 20 6d | 79 20 61 62 69 6c 69 74 |beyond m|y abilit|
|00004370| 79 2e 0d 7d 0d 4e 6f 74 | 65 20 74 68 61 74 20 61 |y..}.Not|e that a|
|00004380| 20 73 65 63 6f 6e 64 61 | 72 79 20 70 72 6f 6d 70 | seconda|ry promp|
|00004390| 74 20 6f 6e 20 61 20 6c | 69 6e 65 20 62 79 20 69 |t on a l|ine by i|
|000043a0| 74 73 65 6c 66 20 69 6e | 20 61 6e 20 65 78 61 6d |tself in| an exam|
|000043b0| 70 6c 65 20 6d 65 61 6e | 73 0d 79 6f 75 20 6d 75 |ple mean|s.you mu|
|000043c0| 73 74 20 74 79 70 65 20 | 61 20 62 6c 61 6e 6b 20 |st type |a blank |
|000043d0| 6c 69 6e 65 3b 20 74 68 | 69 73 20 69 73 20 75 73 |line; th|is is us|
|000043e0| 65 64 20 74 6f 20 65 6e | 64 20 61 20 6d 75 6c 74 |ed to en|d a mult|
|000043f0| 69 2d 6c 69 6e 65 20 63 | 6f 6d 6d 61 6e 64 2e 0d |i-line c|ommand..|
|00004400| 0d 5c 73 65 63 74 69 6f | 6e 7b 55 73 69 6e 67 20 |.\sectio|n{Using |
|00004410| 50 79 74 68 6f 6e 20 61 | 73 20 61 20 43 61 6c 63 |Python a|s a Calc|
|00004420| 75 6c 61 74 6f 72 7d 0d | 0d 4c 65 74 27 73 20 74 |ulator}.|.Let's t|
|00004430| 72 79 20 73 6f 6d 65 20 | 73 69 6d 70 6c 65 20 50 |ry some |simple P|
|00004440| 79 74 68 6f 6e 20 63 6f | 6d 6d 61 6e 64 73 2e 20 |ython co|mmands. |
|00004450| 20 53 74 61 72 74 20 74 | 68 65 20 69 6e 74 65 72 | Start t|he inter|
|00004460| 70 72 65 74 65 72 20 61 | 6e 64 20 77 61 69 74 0d |preter a|nd wait.|
|00004470| 66 6f 72 20 74 68 65 20 | 70 72 69 6d 61 72 79 20 |for the |primary |
|00004480| 70 72 6f 6d 70 74 2c 20 | 7b 5c 74 74 20 3e 3e 3e |prompt, |{\tt >>>|
|00004490| 7d 2e 20 20 28 49 74 20 | 73 68 6f 75 6c 64 6e 27 |}. (It |shouldn'|
|000044a0| 74 20 74 61 6b 65 20 6c | 6f 6e 67 2e 29 0d 0d 5c |t take l|ong.)..\|
|000044b0| 73 75 62 73 65 63 74 69 | 6f 6e 7b 4e 75 6d 62 65 |subsecti|on{Numbe|
|000044c0| 72 73 7d 0d 0d 54 68 65 | 20 69 6e 74 65 72 70 72 |rs}..The| interpr|
|000044d0| 65 74 65 72 20 61 63 74 | 73 20 61 73 20 61 20 73 |eter act|s as a s|
|000044e0| 69 6d 70 6c 65 20 63 61 | 6c 63 75 6c 61 74 6f 72 |imple ca|lculator|
|000044f0| 3a 20 79 6f 75 20 63 61 | 6e 20 74 79 70 65 20 61 |: you ca|n type a|
|00004500| 6e 0d 65 78 70 72 65 73 | 73 69 6f 6e 20 61 74 20 |n.expres|sion at |
|00004510| 69 74 20 61 6e 64 20 69 | 74 20 77 69 6c 6c 20 77 |it and i|t will w|
|00004520| 72 69 74 65 20 74 68 65 | 20 76 61 6c 75 65 2e 20 |rite the| value. |
|00004530| 20 45 78 70 72 65 73 73 | 69 6f 6e 20 73 79 6e 74 | Express|ion synt|
|00004540| 61 78 20 69 73 0d 73 74 | 72 61 69 67 68 74 66 6f |ax is.st|raightfo|
|00004550| 72 77 61 72 64 3a 20 74 | 68 65 20 6f 70 65 72 61 |rward: t|he opera|
|00004560| 74 6f 72 73 20 7b 5c 74 | 74 20 2b 7d 2c 20 7b 5c |tors {\t|t +}, {\|
|00004570| 74 74 20 2d 7d 2c 20 7b | 5c 74 74 20 2a 7d 20 61 |tt -}, {|\tt *} a|
|00004580| 6e 64 20 7b 5c 74 74 20 | 2f 7d 0d 77 6f 72 6b 20 |nd {\tt |/}.work |
|00004590| 6a 75 73 74 20 6c 69 6b | 65 20 69 6e 20 6d 6f 73 |just lik|e in mos|
|000045a0| 74 20 6f 74 68 65 72 20 | 6c 61 6e 67 75 61 67 65 |t other |language|
|000045b0| 73 20 28 65 2e 67 2e 2c | 20 50 61 73 63 61 6c 20 |s (e.g.,| Pascal |
|000045c0| 6f 72 20 43 29 3b 20 70 | 61 72 65 6e 74 68 65 73 |or C); p|arenthes|
|000045d0| 65 73 0d 63 61 6e 20 62 | 65 20 75 73 65 64 20 66 |es.can b|e used f|
|000045e0| 6f 72 20 67 72 6f 75 70 | 69 6e 67 2e 20 20 46 6f |or group|ing. Fo|
|000045f0| 72 20 65 78 61 6d 70 6c | 65 3a 0d 0d 5c 62 63 6f |r exampl|e:..\bco|
|00004600| 64 65 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |de\begin|{verbati|
|00004610| 6d 7d 0d 3e 3e 3e 20 32 | 2b 32 0d 34 0d 3e 3e 3e |m}.>>> 2|+2.4.>>>|
|00004620| 20 23 20 54 68 69 73 20 | 69 73 20 61 20 63 6f 6d | # This |is a com|
|00004630| 6d 65 6e 74 0d 2e 2e 2e | 20 32 2b 32 0d 34 0d 3e |ment....| 2+2.4.>|
|00004640| 3e 3e 20 32 2b 32 20 20 | 23 20 61 6e 64 20 61 20 |>> 2+2 |# and a |
|00004650| 63 6f 6d 6d 65 6e 74 20 | 6f 6e 20 74 68 65 20 73 |comment |on the s|
|00004660| 61 6d 65 20 6c 69 6e 65 | 20 61 73 20 63 6f 64 65 |ame line| as code|
|00004670| 0d 34 0d 3e 3e 3e 20 28 | 35 30 2d 35 2a 36 29 2f |.4.>>> (|50-5*6)/|
|00004680| 34 0d 35 0d 3e 3e 3e 20 | 23 20 49 6e 74 65 67 65 |4.5.>>> |# Intege|
|00004690| 72 20 64 69 76 69 73 69 | 6f 6e 20 72 65 74 75 72 |r divisi|on retur|
|000046a0| 6e 73 20 74 68 65 20 66 | 6c 6f 6f 72 3a 0d 2e 2e |ns the f|loor:...|
|000046b0| 2e 20 37 2f 33 0d 32 0d | 3e 3e 3e 20 37 2f 2d 33 |. 7/3.2.|>>> 7/-3|
|000046c0| 0d 2d 33 0d 3e 3e 3e 20 | 0d 5c 65 6e 64 7b 76 65 |.-3.>>> |.\end{ve|
|000046d0| 72 62 61 74 69 6d 7d 5c | 65 63 6f 64 65 0d 25 0d |rbatim}\|ecode.%.|
|000046e0| 4c 69 6b 65 20 69 6e 20 | 43 2c 20 74 68 65 20 65 |Like in |C, the e|
|000046f0| 71 75 61 6c 20 73 69 67 | 6e 20 28 7b 5c 74 74 20 |qual sig|n ({\tt |
|00004700| 3d 7d 29 20 69 73 20 75 | 73 65 64 20 74 6f 20 61 |=}) is u|sed to a|
|00004710| 73 73 69 67 6e 20 61 20 | 76 61 6c 75 65 20 74 6f |ssign a |value to|
|00004720| 20 61 0d 76 61 72 69 61 | 62 6c 65 2e 20 20 54 68 | a.varia|ble. Th|
|00004730| 65 20 76 61 6c 75 65 20 | 6f 66 20 61 6e 20 61 73 |e value |of an as|
|00004740| 73 69 67 6e 6d 65 6e 74 | 20 69 73 20 6e 6f 74 20 |signment| is not |
|00004750| 77 72 69 74 74 65 6e 3a | 0d 0d 5c 62 63 6f 64 65 |written:|..\bcode|
|00004760| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00004770| 0d 3e 3e 3e 20 77 69 64 | 74 68 20 3d 20 32 30 0d |.>>> wid|th = 20.|
|00004780| 3e 3e 3e 20 68 65 69 67 | 68 74 20 3d 20 35 2a 39 |>>> heig|ht = 5*9|
|00004790| 0d 3e 3e 3e 20 77 69 64 | 74 68 20 2a 20 68 65 69 |.>>> wid|th * hei|
|000047a0| 67 68 74 0d 39 30 30 0d | 3e 3e 3e 20 0d 5c 65 6e |ght.900.|>>> .\en|
|000047b0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|000047c0| 65 0d 25 0d 41 20 76 61 | 6c 75 65 20 63 61 6e 20 |e.%.A va|lue can |
|000047d0| 62 65 20 61 73 73 69 67 | 6e 65 64 20 74 6f 20 73 |be assig|ned to s|
|000047e0| 65 76 65 72 61 6c 20 76 | 61 72 69 61 62 6c 65 73 |everal v|ariables|
|000047f0| 20 73 69 6d 75 6c 74 61 | 6e 65 6f 75 73 6c 79 3a | simulta|neously:|
|00004800| 0d 0d 5c 62 63 6f 64 65 | 5c 62 65 67 69 6e 7b 76 |..\bcode|\begin{v|
|00004810| 65 72 62 61 74 69 6d 7d | 0d 3e 3e 3e 20 78 20 3d |erbatim}|.>>> x =|
|00004820| 20 79 20 3d 20 7a 20 3d | 20 30 20 20 23 20 5a 65 | y = z =| 0 # Ze|
|00004830| 72 6f 20 78 2c 20 79 20 | 61 6e 64 20 7a 0d 3e 3e |ro x, y |and z.>>|
|00004840| 3e 20 78 0d 30 0d 3e 3e | 3e 20 79 0d 30 0d 3e 3e |> x.0.>>|> y.0.>>|
|00004850| 3e 20 7a 0d 30 0d 3e 3e | 3e 20 0d 5c 65 6e 64 7b |> z.0.>>|> .\end{|
|00004860| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0d |verbatim|}\ecode.|
|00004870| 25 0d 54 68 65 72 65 20 | 69 73 20 66 75 6c 6c 20 |%.There |is full |
|00004880| 73 75 70 70 6f 72 74 20 | 66 6f 72 20 66 6c 6f 61 |support |for floa|
|00004890| 74 69 6e 67 20 70 6f 69 | 6e 74 3b 20 6f 70 65 72 |ting poi|nt; oper|
|000048a0| 61 74 6f 72 73 20 77 69 | 74 68 20 6d 69 78 65 64 |ators wi|th mixed|
|000048b0| 20 74 79 70 65 0d 6f 70 | 65 72 61 6e 64 73 20 63 | type.op|erands c|
|000048c0| 6f 6e 76 65 72 74 20 74 | 68 65 20 69 6e 74 65 67 |onvert t|he integ|
|000048d0| 65 72 20 6f 70 65 72 61 | 6e 64 20 74 6f 20 66 6c |er opera|nd to fl|
|000048e0| 6f 61 74 69 6e 67 20 70 | 6f 69 6e 74 3a 0d 0d 5c |oating p|oint:..\|
|000048f0| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|00004900| 61 74 69 6d 7d 0d 3e 3e | 3e 20 34 20 2a 20 32 2e |atim}.>>|> 4 * 2.|
|00004910| 35 20 2f 20 33 2e 33 0d | 33 2e 30 33 30 33 30 33 |5 / 3.3.|3.030303|
|00004920| 30 33 30 33 0d 3e 3e 3e | 20 37 2e 30 20 2f 20 32 |0303.>>>| 7.0 / 2|
|00004930| 0d 33 2e 35 0d 3e 3e 3e | 20 0d 5c 65 6e 64 7b 76 |.3.5.>>>| .\end{v|
|00004940| 65 72 62 61 74 69 6d 7d | 5c 65 63 6f 64 65 0d 0d |erbatim}|\ecode..|
|00004950| 5c 73 75 62 73 65 63 74 | 69 6f 6e 7b 53 74 72 69 |\subsect|ion{Stri|
|00004960| 6e 67 73 7d 0d 0d 42 65 | 73 69 64 65 73 20 6e 75 |ngs}..Be|sides nu|
|00004970| 6d 62 65 72 73 2c 20 50 | 79 74 68 6f 6e 20 63 61 |mbers, P|ython ca|
|00004980| 6e 20 61 6c 73 6f 20 6d | 61 6e 69 70 75 6c 61 74 |n also m|anipulat|
|00004990| 65 20 73 74 72 69 6e 67 | 73 2c 20 65 6e 63 6c 6f |e string|s, enclo|
|000049a0| 73 65 64 20 69 6e 0d 73 | 69 6e 67 6c 65 20 71 75 |sed in.s|ingle qu|
|000049b0| 6f 74 65 73 20 6f 72 20 | 64 6f 75 62 6c 65 20 71 |otes or |double q|
|000049c0| 75 6f 74 65 73 3a 0d 0d | 5c 62 63 6f 64 65 5c 62 |uotes:..|\bcode\b|
|000049d0| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0d 3e |egin{ver|batim}.>|
|000049e0| 3e 3e 20 27 66 6f 6f 20 | 62 61 72 27 0d 27 66 6f |>> 'foo |bar'.'fo|
|000049f0| 6f 20 62 61 72 27 0d 3e | 3e 3e 20 27 64 6f 65 73 |o bar'.>|>> 'does|
|00004a00| 6e 5c 27 74 27 0d 22 64 | 6f 65 73 6e 27 74 22 0d |n\'t'."d|oesn't".|
|00004a10| 3e 3e 3e 20 22 64 6f 65 | 73 6e 27 74 22 0d 22 64 |>>> "doe|sn't"."d|
|00004a20| 6f 65 73 6e 27 74 22 0d | 3e 3e 3e 20 27 22 59 65 |oesn't".|>>> '"Ye|
|00004a30| 73 2c 22 20 68 65 20 73 | 61 69 64 2e 27 0d 27 22 |s," he s|aid.'.'"|
|00004a40| 59 65 73 2c 22 20 68 65 | 20 73 61 69 64 2e 27 0d |Yes," he| said.'.|
|00004a50| 3e 3e 3e 20 22 5c 22 59 | 65 73 2c 5c 22 20 68 65 |>>> "\"Y|es,\" he|
|00004a60| 20 73 61 69 64 2e 22 0d | 27 22 59 65 73 2c 22 20 | said.".|'"Yes," |
|00004a70| 68 65 20 73 61 69 64 2e | 27 0d 3e 3e 3e 20 27 22 |he said.|'.>>> '"|
|00004a80| 49 73 6e 5c 27 74 2c 22 | 20 73 68 65 20 73 61 69 |Isn\'t,"| she sai|
|00004a90| 64 2e 27 0d 27 22 49 73 | 6e 5c 27 74 2c 22 20 73 |d.'.'"Is|n\'t," s|
|00004aa0| 68 65 20 73 61 69 64 2e | 27 0d 3e 3e 3e 20 0d 5c |he said.|'.>>> .\|
|00004ab0| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 5c 65 63 |end{verb|atim}\ec|
|00004ac0| 6f 64 65 0d 25 0d 53 74 | 72 69 6e 67 73 20 61 72 |ode.%.St|rings ar|
|00004ad0| 65 20 77 72 69 74 74 65 | 6e 20 74 68 65 20 73 61 |e writte|n the sa|
|00004ae0| 6d 65 20 77 61 79 20 61 | 73 20 74 68 65 79 20 61 |me way a|s they a|
|00004af0| 72 65 20 74 79 70 65 64 | 20 66 6f 72 20 69 6e 70 |re typed| for inp|
|00004b00| 75 74 3a 20 69 6e 73 69 | 64 65 0d 71 75 6f 74 65 |ut: insi|de.quote|
|00004b10| 73 20 61 6e 64 20 77 69 | 74 68 20 71 75 6f 74 65 |s and wi|th quote|
|00004b20| 73 20 61 6e 64 20 6f 74 | 68 65 72 20 66 75 6e 6e |s and ot|her funn|
|00004b30| 79 20 63 68 61 72 61 63 | 74 65 72 73 20 65 73 63 |y charac|ters esc|
|00004b40| 61 70 65 64 20 62 79 20 | 62 61 63 6b 73 6c 61 73 |aped by |backslas|
|00004b50| 68 65 73 2c 0d 74 6f 20 | 73 68 6f 77 20 74 68 65 |hes,.to |show the|
|00004b60| 20 70 72 65 63 69 73 65 | 20 76 61 6c 75 65 2e 20 | precise| value. |
|00004b70| 20 54 68 65 20 73 74 72 | 69 6e 67 20 69 73 20 65 | The str|ing is e|
|00004b80| 6e 63 6c 6f 73 65 64 20 | 69 6e 20 64 6f 75 62 6c |nclosed |in doubl|
|00004b90| 65 20 71 75 6f 74 65 73 | 20 69 66 0d 74 68 65 20 |e quotes| if.the |
|00004ba0| 73 74 72 69 6e 67 20 63 | 6f 6e 74 61 69 6e 73 20 |string c|ontains |
|00004bb0| 61 20 73 69 6e 67 6c 65 | 20 71 75 6f 74 65 20 61 |a single| quote a|
|00004bc0| 6e 64 20 6e 6f 20 64 6f | 75 62 6c 65 20 71 75 6f |nd no do|uble quo|
|00004bd0| 74 65 73 2c 20 65 6c 73 | 65 20 69 74 27 73 0d 65 |tes, els|e it's.e|
|00004be0| 6e 63 6c 6f 73 65 64 20 | 69 6e 20 73 69 6e 67 6c |nclosed |in singl|
|00004bf0| 65 20 71 75 6f 74 65 73 | 2e 20 20 28 54 68 65 20 |e quotes|. (The |
|00004c00| 7b 5c 74 74 20 70 72 69 | 6e 74 7d 20 73 74 61 74 |{\tt pri|nt} stat|
|00004c10| 65 6d 65 6e 74 2c 20 64 | 65 73 63 72 69 62 65 64 |ement, d|escribed|
|00004c20| 20 6c 61 74 65 72 2c 0d | 63 61 6e 20 62 65 20 75 | later,.|can be u|
|00004c30| 73 65 64 20 74 6f 20 77 | 72 69 74 65 20 73 74 72 |sed to w|rite str|
|00004c40| 69 6e 67 73 20 77 69 74 | 68 6f 75 74 20 71 75 6f |ings wit|hout quo|
|00004c50| 74 65 73 20 6f 72 20 65 | 73 63 61 70 65 73 2e 29 |tes or e|scapes.)|
|00004c60| 0d 0d 53 74 72 69 6e 67 | 73 20 63 61 6e 20 62 65 |..String|s can be|
|00004c70| 20 63 6f 6e 63 61 74 65 | 6e 61 74 65 64 20 28 67 | concate|nated (g|
|00004c80| 6c 75 65 64 20 74 6f 67 | 65 74 68 65 72 29 20 77 |lued tog|ether) w|
|00004c90| 69 74 68 20 74 68 65 20 | 7b 5c 74 74 20 2b 7d 0d |ith the |{\tt +}.|
|00004ca0| 6f 70 65 72 61 74 6f 72 | 2c 20 61 6e 64 20 72 65 |operator|, and re|
|00004cb0| 70 65 61 74 65 64 20 77 | 69 74 68 20 7b 5c 74 74 |peated w|ith {\tt|
|00004cc0| 20 2a 7d 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 | *}:..\b|code\beg|
|00004cd0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|00004ce0| 20 77 6f 72 64 20 3d 20 | 27 48 65 6c 70 27 20 2b | word = |'Help' +|
|00004cf0| 20 27 41 27 0d 3e 3e 3e | 20 77 6f 72 64 0d 27 48 | 'A'.>>>| word.'H|
|00004d00| 65 6c 70 41 27 0d 3e 3e | 3e 20 27 3c 27 20 2b 20 |elpA'.>>|> '<' + |
|00004d10| 77 6f 72 64 2a 35 20 2b | 20 27 3e 27 0d 27 3c 48 |word*5 +| '>'.'<H|
|00004d20| 65 6c 70 41 48 65 6c 70 | 41 48 65 6c 70 41 48 65 |elpAHelp|AHelpAHe|
|00004d30| 6c 70 41 48 65 6c 70 41 | 3e 27 0d 3e 3e 3e 20 0d |lpAHelpA|>'.>>> .|
|00004d40| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00004d50| 63 6f 64 65 0d 25 0d 53 | 74 72 69 6e 67 73 20 63 |code.%.S|trings c|
|00004d60| 61 6e 20 62 65 20 73 75 | 62 73 63 72 69 70 74 65 |an be su|bscripte|
|00004d70| 64 20 28 69 6e 64 65 78 | 65 64 29 3b 20 6c 69 6b |d (index|ed); lik|
|00004d80| 65 20 69 6e 20 43 2c 20 | 74 68 65 20 66 69 72 73 |e in C, |the firs|
|00004d90| 74 20 63 68 61 72 61 63 | 74 65 72 20 6f 66 0d 61 |t charac|ter of.a|
|00004da0| 20 73 74 72 69 6e 67 20 | 68 61 73 20 73 75 62 73 | string |has subs|
|00004db0| 63 72 69 70 74 20 28 69 | 6e 64 65 78 29 20 30 2e |cript (i|ndex) 0.|
|00004dc0| 0d 0d 54 68 65 72 65 20 | 69 73 20 6e 6f 20 73 65 |..There |is no se|
|00004dd0| 70 61 72 61 74 65 20 63 | 68 61 72 61 63 74 65 72 |parate c|haracter|
|00004de0| 20 74 79 70 65 3b 20 61 | 20 63 68 61 72 61 63 74 | type; a| charact|
|00004df0| 65 72 20 69 73 20 73 69 | 6d 70 6c 79 20 61 20 73 |er is si|mply a s|
|00004e00| 74 72 69 6e 67 20 6f 66 | 0d 73 69 7a 65 20 6f 6e |tring of|.size on|
|00004e10| 65 2e 20 20 4c 69 6b 65 | 20 69 6e 20 49 63 6f 6e |e. Like| in Icon|
|00004e20| 2c 20 73 75 62 73 74 72 | 69 6e 67 73 20 63 61 6e |, substr|ings can|
|00004e30| 20 62 65 20 73 70 65 63 | 69 66 69 65 64 20 77 69 | be spec|ified wi|
|00004e40| 74 68 20 74 68 65 20 7b | 5c 65 6d 0d 73 6c 69 63 |th the {|\em.slic|
|00004e50| 65 7d 20 6e 6f 74 61 74 | 69 6f 6e 3a 20 74 77 6f |e} notat|ion: two|
|00004e60| 20 69 6e 64 69 63 65 73 | 20 73 65 70 61 72 61 74 | indices| separat|
|00004e70| 65 64 20 62 79 20 61 20 | 63 6f 6c 6f 6e 2e 0d 0d |ed by a |colon...|
|00004e80| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00004e90| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 77 6f 72 64 5b |batim}.>|>> word[|
|00004ea0| 34 5d 0d 27 41 27 0d 3e | 3e 3e 20 77 6f 72 64 5b |4].'A'.>|>> word[|
|00004eb0| 30 3a 32 5d 0d 27 48 65 | 27 0d 3e 3e 3e 20 77 6f |0:2].'He|'.>>> wo|
|00004ec0| 72 64 5b 32 3a 34 5d 0d | 27 6c 70 27 0d 3e 3e 3e |rd[2:4].|'lp'.>>>|
|00004ed0| 20 0d 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d | .\end{v|erbatim}|
|00004ee0| 5c 65 63 6f 64 65 0d 25 | 0d 53 6c 69 63 65 20 69 |\ecode.%|.Slice i|
|00004ef0| 6e 64 69 63 65 73 20 68 | 61 76 65 20 75 73 65 66 |ndices h|ave usef|
|00004f00| 75 6c 20 64 65 66 61 75 | 6c 74 73 3b 20 61 6e 20 |ul defau|lts; an |
|00004f10| 6f 6d 69 74 74 65 64 20 | 66 69 72 73 74 20 69 6e |omitted |first in|
|00004f20| 64 65 78 20 64 65 66 61 | 75 6c 74 73 20 74 6f 0d |dex defa|ults to.|
|00004f30| 7a 65 72 6f 2c 20 61 6e | 20 6f 6d 69 74 74 65 64 |zero, an| omitted|
|00004f40| 20 73 65 63 6f 6e 64 20 | 69 6e 64 65 78 20 64 65 | second |index de|
|00004f50| 66 61 75 6c 74 73 20 74 | 6f 20 74 68 65 20 73 69 |faults t|o the si|
|00004f60| 7a 65 20 6f 66 20 74 68 | 65 20 73 74 72 69 6e 67 |ze of th|e string|
|00004f70| 20 62 65 69 6e 67 0d 73 | 6c 69 63 65 64 2e 0d 0d | being.s|liced...|
|00004f80| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00004f90| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 77 6f 72 64 5b |batim}.>|>> word[|
|00004fa0| 3a 32 5d 20 20 20 20 23 | 20 54 68 65 20 66 69 72 |:2] #| The fir|
|00004fb0| 73 74 20 74 77 6f 20 63 | 68 61 72 61 63 74 65 72 |st two c|haracter|
|00004fc0| 73 0d 27 48 65 27 0d 3e | 3e 3e 20 77 6f 72 64 5b |s.'He'.>|>> word[|
|00004fd0| 32 3a 5d 20 20 20 20 23 | 20 41 6c 6c 20 62 75 74 |2:] #| All but|
|00004fe0| 20 74 68 65 20 66 69 72 | 73 74 20 74 77 6f 20 63 | the fir|st two c|
|00004ff0| 68 61 72 61 63 74 65 72 | 73 0d 27 6c 70 41 27 0d |haracter|s.'lpA'.|
|00005000| 3e 3e 3e 0d 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |>>>.\end|{verbati|
|00005010| 6d 7d 5c 65 63 6f 64 65 | 0d 25 0d 48 65 72 65 27 |m}\ecode|.%.Here'|
|00005020| 73 20 61 20 75 73 65 66 | 75 6c 20 69 6e 76 61 72 |s a usef|ul invar|
|00005030| 69 61 6e 74 20 6f 66 20 | 73 6c 69 63 65 20 6f 70 |iant of |slice op|
|00005040| 65 72 61 74 69 6f 6e 73 | 3a 20 5c 76 65 72 62 5c |erations|: \verb\|
|00005050| 73 5b 3a 69 5d 20 2b 20 | 73 5b 69 3a 5d 5c 0d 65 |s[:i] + |s[i:]\.e|
|00005060| 71 75 61 6c 73 20 5c 76 | 65 72 62 5c 73 5c 2e 0d |quals \v|erb\s\..|
|00005070| 0d 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|00005080| 72 62 61 74 69 6d 7d 0d | 3e 3e 3e 20 77 6f 72 64 |rbatim}.|>>> word|
|00005090| 5b 3a 32 5d 20 2b 20 77 | 6f 72 64 5b 32 3a 5d 0d |[:2] + w|ord[2:].|
|000050a0| 27 48 65 6c 70 41 27 0d | 3e 3e 3e 20 77 6f 72 64 |'HelpA'.|>>> word|
|000050b0| 5b 3a 33 5d 20 2b 20 77 | 6f 72 64 5b 33 3a 5d 0d |[:3] + w|ord[3:].|
|000050c0| 27 48 65 6c 70 41 27 0d | 3e 3e 3e 20 0d 5c 65 6e |'HelpA'.|>>> .\en|
|000050d0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|000050e0| 65 0d 25 0d 44 65 67 65 | 6e 65 72 61 74 65 20 73 |e.%.Dege|nerate s|
|000050f0| 6c 69 63 65 20 69 6e 64 | 69 63 65 73 20 61 72 65 |lice ind|ices are|
|00005100| 20 68 61 6e 64 6c 65 64 | 20 67 72 61 63 65 66 75 | handled| gracefu|
|00005110| 6c 6c 79 3a 20 61 6e 20 | 69 6e 64 65 78 20 74 68 |lly: an |index th|
|00005120| 61 74 20 69 73 20 74 6f | 6f 0d 6c 61 72 67 65 20 |at is to|o.large |
|00005130| 69 73 20 72 65 70 6c 61 | 63 65 64 20 62 79 20 74 |is repla|ced by t|
|00005140| 68 65 20 73 74 72 69 6e | 67 20 73 69 7a 65 2c 20 |he strin|g size, |
|00005150| 61 6e 20 75 70 70 65 72 | 20 62 6f 75 6e 64 20 73 |an upper| bound s|
|00005160| 6d 61 6c 6c 65 72 20 74 | 68 61 6e 20 74 68 65 0d |maller t|han the.|
|00005170| 6c 6f 77 65 72 20 62 6f | 75 6e 64 20 72 65 74 75 |lower bo|und retu|
|00005180| 72 6e 73 20 61 6e 20 65 | 6d 70 74 79 20 73 74 72 |rns an e|mpty str|
|00005190| 69 6e 67 2e 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |ing...\b|code\beg|
|000051a0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|000051b0| 20 77 6f 72 64 5b 31 3a | 31 30 30 5d 0d 27 65 6c | word[1:|100].'el|
|000051c0| 70 41 27 0d 3e 3e 3e 20 | 77 6f 72 64 5b 31 30 3a |pA'.>>> |word[10:|
|000051d0| 5d 0d 27 27 0d 3e 3e 3e | 20 77 6f 72 64 5b 32 3a |].''.>>>| word[2:|
|000051e0| 31 5d 0d 27 27 0d 3e 3e | 3e 20 0d 5c 65 6e 64 7b |1].''.>>|> .\end{|
|000051f0| 76 65 72 62 61 74 69 6d | 7d 5c 65 63 6f 64 65 0d |verbatim|}\ecode.|
|00005200| 25 0d 49 6e 64 69 63 65 | 73 20 6d 61 79 20 62 65 |%.Indice|s may be|
|00005210| 20 6e 65 67 61 74 69 76 | 65 20 6e 75 6d 62 65 72 | negativ|e number|
|00005220| 73 2c 20 74 6f 20 73 74 | 61 72 74 20 63 6f 75 6e |s, to st|art coun|
|00005230| 74 69 6e 67 20 66 72 6f | 6d 20 74 68 65 20 72 69 |ting fro|m the ri|
|00005240| 67 68 74 2e 0d 46 6f 72 | 20 65 78 61 6d 70 6c 65 |ght..For| example|
|00005250| 3a 0d 0d 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |:..\bcod|e\begin{|
|00005260| 76 65 72 62 61 74 69 6d | 7d 0d 3e 3e 3e 20 77 6f |verbatim|}.>>> wo|
|00005270| 72 64 5b 2d 31 5d 20 20 | 20 20 20 23 20 54 68 65 |rd[-1] | # The|
|00005280| 20 6c 61 73 74 20 63 68 | 61 72 61 63 74 65 72 0d | last ch|aracter.|
|00005290| 27 41 27 0d 3e 3e 3e 20 | 77 6f 72 64 5b 2d 32 5d |'A'.>>> |word[-2]|
|000052a0| 20 20 20 20 20 23 20 54 | 68 65 20 6c 61 73 74 2d | # T|he last-|
|000052b0| 62 75 74 2d 6f 6e 65 20 | 63 68 61 72 61 63 74 65 |but-one |characte|
|000052c0| 72 0d 27 70 27 0d 3e 3e | 3e 20 77 6f 72 64 5b 2d |r.'p'.>>|> word[-|
|000052d0| 32 3a 5d 20 20 20 20 23 | 20 54 68 65 20 6c 61 73 |2:] #| The las|
|000052e0| 74 20 74 77 6f 20 63 68 | 61 72 61 63 74 65 72 73 |t two ch|aracters|
|000052f0| 0d 27 70 41 27 0d 3e 3e | 3e 20 77 6f 72 64 5b 3a |.'pA'.>>|> word[:|
|00005300| 2d 32 5d 20 20 20 20 23 | 20 41 6c 6c 20 62 75 74 |-2] #| All but|
|00005310| 20 74 68 65 20 6c 61 73 | 74 20 74 77 6f 20 63 68 | the las|t two ch|
|00005320| 61 72 61 63 74 65 72 73 | 0d 27 48 65 6c 27 0d 3e |aracters|.'Hel'.>|
|00005330| 3e 3e 0d 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |>>.\end{|verbatim|
|00005340| 7d 5c 65 63 6f 64 65 0d | 25 0d 42 75 74 20 6e 6f |}\ecode.|%.But no|
|00005350| 74 65 20 74 68 61 74 20 | 2d 30 20 69 73 20 72 65 |te that |-0 is re|
|00005360| 61 6c 6c 79 20 74 68 65 | 20 73 61 6d 65 20 61 73 |ally the| same as|
|00005370| 20 30 2c 20 73 6f 20 69 | 74 20 64 6f 65 73 20 6e | 0, so i|t does n|
|00005380| 6f 74 20 63 6f 75 6e 74 | 20 66 72 6f 6d 0d 74 68 |ot count| from.th|
|00005390| 65 20 72 69 67 68 74 21 | 0d 0d 5c 62 63 6f 64 65 |e right!|..\bcode|
|000053a0| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|000053b0| 0d 3e 3e 3e 20 77 6f 72 | 64 5b 2d 30 5d 20 20 20 |.>>> wor|d[-0] |
|000053c0| 20 20 23 20 28 73 69 6e | 63 65 20 2d 30 20 65 71 | # (sin|ce -0 eq|
|000053d0| 75 61 6c 73 20 30 29 0d | 27 48 27 0d 3e 3e 3e 0d |uals 0).|'H'.>>>.|
|000053e0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|000053f0| 63 6f 64 65 0d 25 0d 4f | 75 74 2d 6f 66 2d 72 61 |code.%.O|ut-of-ra|
|00005400| 6e 67 65 20 6e 65 67 61 | 74 69 76 65 20 73 6c 69 |nge nega|tive sli|
|00005410| 63 65 20 69 6e 64 69 63 | 65 73 20 61 72 65 20 74 |ce indic|es are t|
|00005420| 72 75 6e 63 61 74 65 64 | 2c 20 62 75 74 20 64 6f |runcated|, but do|
|00005430| 6e 27 74 20 74 72 79 20 | 74 68 69 73 0d 66 6f 72 |n't try |this.for|
|00005440| 20 73 69 6e 67 6c 65 2d | 65 6c 65 6d 65 6e 74 20 | single-|element |
|00005450| 28 6e 6f 6e 2d 73 6c 69 | 63 65 29 20 69 6e 64 69 |(non-sli|ce) indi|
|00005460| 63 65 73 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |ces:..\b|code\beg|
|00005470| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|00005480| 20 77 6f 72 64 5b 2d 31 | 30 30 3a 5d 0d 27 48 65 | word[-1|00:].'He|
|00005490| 6c 70 41 27 0d 3e 3e 3e | 20 77 6f 72 64 5b 2d 31 |lpA'.>>>| word[-1|
|000054a0| 30 5d 20 20 20 20 23 20 | 65 72 72 6f 72 0d 54 72 |0] # |error.Tr|
|000054b0| 61 63 65 62 61 63 6b 20 | 28 69 6e 6e 65 72 6d 6f |aceback |(innermo|
|000054c0| 73 74 20 6c 61 73 74 29 | 3a 0d 20 20 46 69 6c 65 |st last)|:. File|
|000054d0| 20 22 3c 73 74 64 69 6e | 3e 22 2c 20 6c 69 6e 65 | "<stdin|>", line|
|000054e0| 20 31 0d 49 6e 64 65 78 | 45 72 72 6f 72 3a 20 73 | 1.Index|Error: s|
|000054f0| 74 72 69 6e 67 20 69 6e | 64 65 78 20 6f 75 74 20 |tring in|dex out |
|00005500| 6f 66 20 72 61 6e 67 65 | 0d 3e 3e 3e 20 0d 5c 65 |of range|.>>> .\e|
|00005510| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 5c 65 63 6f |nd{verba|tim}\eco|
|00005520| 64 65 0d 25 0d 54 68 65 | 20 62 65 73 74 20 77 61 |de.%.The| best wa|
|00005530| 79 20 74 6f 20 72 65 6d | 65 6d 62 65 72 20 68 6f |y to rem|ember ho|
|00005540| 77 20 73 6c 69 63 65 73 | 20 77 6f 72 6b 20 69 73 |w slices| work is|
|00005550| 20 74 6f 20 74 68 69 6e | 6b 20 6f 66 20 74 68 65 | to thin|k of the|
|00005560| 20 69 6e 64 69 63 65 73 | 20 61 73 0d 70 6f 69 6e | indices| as.poin|
|00005570| 74 69 6e 67 20 7b 5c 65 | 6d 20 62 65 74 77 65 65 |ting {\e|m betwee|
|00005580| 6e 7d 20 63 68 61 72 61 | 63 74 65 72 73 2c 20 77 |n} chara|cters, w|
|00005590| 69 74 68 20 74 68 65 20 | 6c 65 66 74 20 65 64 67 |ith the |left edg|
|000055a0| 65 20 6f 66 20 74 68 65 | 20 66 69 72 73 74 0d 63 |e of the| first.c|
|000055b0| 68 61 72 61 63 74 65 72 | 20 6e 75 6d 62 65 72 65 |haracter| numbere|
|000055c0| 64 20 30 2e 20 20 54 68 | 65 6e 20 74 68 65 20 72 |d 0. Th|en the r|
|000055d0| 69 67 68 74 20 65 64 67 | 65 20 6f 66 20 74 68 65 |ight edg|e of the|
|000055e0| 20 6c 61 73 74 20 63 68 | 61 72 61 63 74 65 72 20 | last ch|aracter |
|000055f0| 6f 66 20 61 0d 73 74 72 | 69 6e 67 20 6f 66 20 7b |of a.str|ing of {|
|00005600| 5c 74 74 20 6e 7d 20 63 | 68 61 72 61 63 74 65 72 |\tt n} c|haracter|
|00005610| 73 20 68 61 73 20 69 6e | 64 65 78 20 7b 5c 74 74 |s has in|dex {\tt|
|00005620| 20 6e 7d 2c 20 66 6f 72 | 20 65 78 61 6d 70 6c 65 | n}, for| example|
|00005630| 3a 0d 0d 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |:..\bcod|e\begin{|
|00005640| 76 65 72 62 61 74 69 6d | 7d 0d 20 2b 2d 2d 2d 2b |verbatim|}. +---+|
|00005650| 2d 2d 2d 2b 2d 2d 2d 2b | 2d 2d 2d 2b 2d 2d 2d 2b |---+---+|---+---+|
|00005660| 20 0d 20 7c 20 48 20 7c | 20 65 20 7c 20 6c 20 7c | . | H || e | l ||
|00005670| 20 70 20 7c 20 41 20 7c | 0d 20 2b 2d 2d 2d 2b 2d | p | A ||. +---+-|
|00005680| 2d 2d 2b 2d 2d 2d 2b 2d | 2d 2d 2b 2d 2d 2d 2b 20 |--+---+-|--+---+ |
|00005690| 0d 20 30 20 20 20 31 20 | 20 20 32 20 20 20 33 20 |. 0 1 | 2 3 |
|000056a0| 20 20 34 20 20 20 35 20 | 0d 2d 35 20 20 2d 34 20 | 4 5 |.-5 -4 |
|000056b0| 20 2d 33 20 20 2d 32 20 | 20 2d 31 0d 5c 65 6e 64 | -3 -2 | -1.\end|
|000056c0| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|000056d0| 0d 25 0d 54 68 65 20 66 | 69 72 73 74 20 72 6f 77 |.%.The f|irst row|
|000056e0| 20 6f 66 20 6e 75 6d 62 | 65 72 73 20 67 69 76 65 | of numb|ers give|
|000056f0| 73 20 74 68 65 20 70 6f | 73 69 74 69 6f 6e 20 6f |s the po|sition o|
|00005700| 66 20 74 68 65 20 69 6e | 64 69 63 65 73 20 30 2e |f the in|dices 0.|
|00005710| 2e 2e 35 20 69 6e 0d 74 | 68 65 20 73 74 72 69 6e |..5 in.t|he strin|
|00005720| 67 3b 20 74 68 65 20 73 | 65 63 6f 6e 64 20 72 6f |g; the s|econd ro|
|00005730| 77 20 67 69 76 65 73 20 | 74 68 65 20 63 6f 72 72 |w gives |the corr|
|00005740| 65 73 70 6f 6e 64 69 6e | 67 20 6e 65 67 61 74 69 |espondin|g negati|
|00005750| 76 65 20 69 6e 64 69 63 | 65 73 2e 0d 54 68 65 20 |ve indic|es..The |
|00005760| 73 6c 69 63 65 20 66 72 | 6f 6d 20 5c 76 65 72 62 |slice fr|om \verb|
|00005770| 5c 69 5c 20 74 6f 20 5c | 76 65 72 62 5c 6a 5c 20 |\i\ to \|verb\j\ |
|00005780| 63 6f 6e 73 69 73 74 73 | 20 6f 66 20 61 6c 6c 20 |consists| of all |
|00005790| 63 68 61 72 61 63 74 65 | 72 73 20 62 65 74 77 65 |characte|rs betwe|
|000057a0| 65 6e 0d 74 68 65 20 65 | 64 67 65 73 20 6c 61 62 |en.the e|dges lab|
|000057b0| 65 6c 65 64 20 5c 76 65 | 72 62 5c 69 5c 20 61 6e |eled \ve|rb\i\ an|
|000057c0| 64 20 5c 76 65 72 62 5c | 6a 5c 2c 20 72 65 73 70 |d \verb\|j\, resp|
|000057d0| 65 63 74 69 76 65 6c 79 | 2e 0d 0d 46 6f 72 20 6e |ectively|...For n|
|000057e0| 6f 6e 6e 65 67 61 74 69 | 76 65 20 69 6e 64 69 63 |onnegati|ve indic|
|000057f0| 65 73 2c 20 74 68 65 20 | 6c 65 6e 67 74 68 20 6f |es, the |length o|
|00005800| 66 20 61 20 73 6c 69 63 | 65 20 69 73 20 74 68 65 |f a slic|e is the|
|00005810| 20 64 69 66 66 65 72 65 | 6e 63 65 20 6f 66 0d 74 | differe|nce of.t|
|00005820| 68 65 20 69 6e 64 69 63 | 65 73 2c 20 69 66 20 62 |he indic|es, if b|
|00005830| 6f 74 68 20 61 72 65 20 | 77 69 74 68 69 6e 20 62 |oth are |within b|
|00005840| 6f 75 6e 64 73 2c 20 65 | 2e 67 2e 2c 20 74 68 65 |ounds, e|.g., the|
|00005850| 20 6c 65 6e 67 74 68 20 | 6f 66 0d 5c 76 65 72 62 | length |of.\verb|
|00005860| 5c 77 6f 72 64 5b 31 3a | 33 5d 5c 20 69 73 20 32 |\word[1:|3]\ is 2|
|00005870| 2e 0d 0d 54 68 65 20 62 | 75 69 6c 74 2d 69 6e 20 |...The b|uilt-in |
|00005880| 66 75 6e 63 74 69 6f 6e | 20 7b 5c 74 74 20 6c 65 |function| {\tt le|
|00005890| 6e 28 29 7d 20 72 65 74 | 75 72 6e 73 20 74 68 65 |n()} ret|urns the|
|000058a0| 20 6c 65 6e 67 74 68 20 | 6f 66 20 61 20 73 74 72 | length |of a str|
|000058b0| 69 6e 67 3a 0d 0d 5c 62 | 63 6f 64 65 5c 62 65 67 |ing:..\b|code\beg|
|000058c0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0d 3e 3e 3e |in{verba|tim}.>>>|
|000058d0| 20 73 20 3d 20 27 73 75 | 70 65 72 63 61 6c 69 66 | s = 'su|percalif|
|000058e0| 72 61 67 69 6c 69 73 74 | 69 63 65 78 70 69 61 6c |ragilist|icexpial|
|000058f0| 69 64 6f 63 69 6f 75 73 | 27 0d 3e 3e 3e 20 6c 65 |idocious|'.>>> le|
|00005900| 6e 28 73 29 0d 33 34 0d | 3e 3e 3e 20 0d 5c 65 6e |n(s).34.|>>> .\en|
|00005910| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00005920| 65 0d 0d 5c 73 75 62 73 | 65 63 74 69 6f 6e 7b 4c |e..\subs|ection{L|
|00005930| 69 73 74 73 7d 0d 0d 50 | 79 74 68 6f 6e 20 6b 6e |ists}..P|ython kn|
|00005940| 6f 77 73 20 61 20 6e 75 | 6d 62 65 72 20 6f 66 20 |ows a nu|mber of |
|00005950| 7b 5c 65 6d 20 63 6f 6d | 70 6f 75 6e 64 7d 20 64 |{\em com|pound} d|
|00005960| 61 74 61 20 74 79 70 65 | 73 2c 20 75 73 65 64 20 |ata type|s, used |
|00005970| 74 6f 20 67 72 6f 75 70 | 0d 74 6f 67 65 74 68 65 |to group|.togethe|
|00005980| 72 20 6f 74 68 65 72 20 | 76 61 6c 75 65 73 2e 20 |r other |values. |
|00005990| 20 54 68 65 20 6d 6f 73 | 74 20 76 65 72 73 61 74 | The mos|t versat|
|000059a0| 69 6c 65 20 69 73 20 74 | 68 65 20 7b 5c 65 6d 20 |ile is t|he {\em |
|000059b0| 6c 69 73 74 7d 2c 20 77 | 68 69 63 68 0d 63 61 6e |list}, w|hich.can|
|000059c0| 20 62 65 20 77 72 69 74 | 74 65 6e 20 61 73 20 61 | be writ|ten as a|
|000059d0| 20 6c 69 73 74 20 6f 66 | 20 63 6f 6d 6d 61 2d 73 | list of| comma-s|
|000059e0| 65 70 61 72 61 74 65 64 | 20 76 61 6c 75 65 73 20 |eparated| values |
|000059f0| 28 69 74 65 6d 73 29 20 | 62 65 74 77 65 65 6e 0d |(items) |between.|
|00005a00| 73 71 75 61 72 65 20 62 | 72 61 63 6b 65 74 73 2e |square b|rackets.|
|00005a10| 20 20 4c 69 73 74 20 69 | 74 65 6d 73 20 6e 65 65 | List i|tems nee|
|00005a20| 64 20 6e 6f 74 20 61 6c | 6c 20 68 61 76 65 20 74 |d not al|l have t|
|00005a30| 68 65 20 73 61 6d 65 20 | 74 79 70 65 2e 0d 0d 5c |he same |type...\|
|00005a40| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|00005a50| 61 74 69 6d 7d 0d 3e 3e | 3e 20 61 20 3d 20 5b 27 |atim}.>>|> a = ['|
|00005a60| 66 6f 6f 27 2c 20 27 62 | 61 72 27 2c 20 31 30 30 |foo', 'b|ar', 100|
|00005a70| 2c 20 31 32 33 34 5d 0d | 3e 3e 3e 20 61 0d 5b 27 |, 1234].|>>> a.['|
|00005a80| 66 6f 6f 27 2c 20 27 62 | 61 72 27 2c 20 31 30 30 |foo', 'b|ar', 100|
|00005a90| 2c 20 31 32 33 34 5d 0d | 3e 3e 3e 20 0d 5c 65 6e |, 1234].|>>> .\en|
|00005aa0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 5c 65 63 6f 64 |d{verbat|im}\ecod|
|00005ab0| 65 0d 25 0d 4c 69 6b 65 | 20 73 74 72 69 6e 67 20 |e.%.Like| string |
|00005ac0| 69 6e 64 69 63 65 73 2c | 20 6c 69 73 74 20 69 6e |indices,| list in|
|00005ad0| 64 69 63 65 73 20 73 74 | 61 72 74 20 61 74 20 30 |dices st|art at 0|
|00005ae0| 2c 20 61 6e 64 20 6c 69 | 73 74 73 20 63 61 6e 20 |, and li|sts can |
|00005af0| 62 65 20 73 6c 69 63 65 | 64 2c 0d 63 6f 6e 63 61 |be slice|d,.conca|
|00005b00| 74 65 6e 61 74 65 64 20 | 61 6e 64 20 73 6f 20 6f |tenated |and so o|
|00005b10| 6e 3a 0d 0d 5c 62 63 6f | 64 65 5c 62 65 67 69 6e |n:..\bco|de\begin|
|00005b20| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 3e 3e 3e 20 61 |{verbati|m}.>>> a|
|00005b30| 5b 30 5d 0d 27 66 6f 6f | 27 0d 3e 3e 3e 20 61 5b |[0].'foo|'.>>> a[|
|00005b40| 33 5d 0d 31 32 33 34 0d | 3e 3e 3e 20 61 5b 2d 32 |3].1234.|>>> a[-2|
|00005b50| 5d 0d 31 30 30 0d 3e 3e | 3e 20 61 5b 31 3a 2d 31 |].100.>>|> a[1:-1|
|00005b60| 5d 0d 5b 27 62 61 72 27 | 2c 20 31 30 30 5d 0d 3e |].['bar'|, 100].>|
|00005b70| 3e 3e 20 61 5b 3a 32 5d | 20 2b 20 5b 27 62 6c 65 |>> a[:2]| + ['ble|
|00005b80| 74 63 68 27 2c 20 32 2a | 32 5d 0d 5b 27 66 6f 6f |tch', 2*|2].['foo|
|00005b90| 27 2c 20 27 62 61 72 27 | 2c 20 27 62 6c 65 74 63 |', 'bar'|, 'bletc|
|00005ba0| 68 27 2c 20 34 5d 0d 3e | 3e 3e 20 33 2a 61 5b 3a |h', 4].>|>> 3*a[:|
|00005bb0| 33 5d 20 2b 20 5b 27 42 | 6f 65 21 27 5d 0d 5b 27 |3] + ['B|oe!'].['|
|00005bc0| 66 6f 6f 27 2c 20 27 62 | 61 72 27 2c 20 31 30 30 |foo', 'b|ar', 100|
|00005bd0| 2c 20 27 66 6f 6f 27 2c | 20 27 62 61 72 27 2c 20 |, 'foo',| 'bar', |
|00005be0| 31 30 30 2c 20 27 66 6f | 6f 27 2c 20 27 62 61 72 |100, 'fo|o', 'bar|
|00005bf0| 27 2c 20 31 30 30 2c 20 | 27 42 6f 65 21 27 5d 0d |', 100, |'Boe!'].|
|00005c00| 3e 3e 3e 20 0d 5c 65 6e | 64 7b 76 65 72 62 61 74 |>>> .\en|d{verbat|
|00005c10| 69 6d 7d 5c 65 63 6f 64 | 65 0d 25 0d 55 6e 6c 69 |im}\ecod|e.%.Unli|
|00005c20| 6b 65 20 73 74 72 69 6e | 67 73 2c 20 77 68 69 63 |ke strin|gs, whic|
|00005c30| 68 20 61 72 65 20 7b 5c | 65 6d 20 69 6d 6d 75 74 |h are {\|em immut|
|00005c40| 61 62 6c 65 7d 2c 20 69 | 74 20 69 73 20 70 6f 73 |able}, i|t is pos|
|00005c50| 73 69 62 6c 65 20 74 6f | 20 63 68 61 6e 67 65 0d |sible to| change.|
|00005c60| 69 6e 64 69 76 69 64 75 | 61 6c 20 65 6c 65 6d 65 |individu|al eleme|
|00005c70| 6e 74 73 20 6f 66 20 61 | 20 6c 69 73 74 3a 0d 0d |nts of a| list:..|
|00005c80| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00005c90| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 61 0d 5b 27 66 |batim}.>|>> a.['f|
|00005ca0| 6f 6f 27 2c 20 27 62 61 | 72 27 2c 20 31 30 30 2c |oo', 'ba|r', 100,|
|00005cb0| 20 31 32 33 34 5d 0d 3e | 3e 3e 20 61 5b 32 5d 20 | 1234].>|>> a[2] |
|00005cc0| 3d 20 61 5b 32 5d 20 2b | 20 32 33 0d 3e 3e 3e 20 |= a[2] +| 23.>>> |
|00005cd0| 61 0d 5b 27 66 6f 6f 27 | 2c 20 27 62 61 72 27 2c |a.['foo'|, 'bar',|
|00005ce0| 20 31 32 33 2c 20 31 32 | 33 34 5d 0d 3e 3e 3e 0d | 123, 12|34].>>>.|
|00005cf0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00005d00| 63 6f 64 65 0d 25 0d 41 | 73 73 69 67 6e 6d 65 6e |code.%.A|ssignmen|
|00005d10| 74 20 74 6f 20 73 6c 69 | 63 65 73 20 69 73 20 61 |t to sli|ces is a|
|00005d20| 6c 73 6f 20 70 6f 73 73 | 69 62 6c 65 2c 20 61 6e |lso poss|ible, an|
|00005d30| 64 20 74 68 69 73 20 63 | 61 6e 20 65 76 65 6e 20 |d this c|an even |
|00005d40| 63 68 61 6e 67 65 20 74 | 68 65 20 73 69 7a 65 0d |change t|he size.|
|00005d50| 6f 66 20 74 68 65 20 6c | 69 73 74 3a 0d 0d 5c 62 |of the l|ist:..\b|
|00005d60| 63 6f 64 65 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |code\beg|in{verba|
|00005d70| 74 69 6d 7d 0d 3e 3e 3e | 20 23 20 52 65 70 6c 61 |tim}.>>>| # Repla|
|00005d80| 63 65 20 73 6f 6d 65 20 | 69 74 65 6d 73 3a 0d 2e |ce some |items:..|
|00005d90| 2e 2e 20 61 5b 30 3a 32 | 5d 20 3d 20 5b 31 2c 20 |.. a[0:2|] = [1, |
|00005da0| 31 32 5d 0d 3e 3e 3e 20 | 61 0d 5b 31 2c 20 31 32 |12].>>> |a.[1, 12|
|00005db0| 2c 20 31 32 33 2c 20 31 | 32 33 34 5d 0d 3e 3e 3e |, 123, 1|234].>>>|
|00005dc0| 20 23 20 52 65 6d 6f 76 | 65 20 73 6f 6d 65 3a 0d | # Remov|e some:.|
|00005dd0| 2e 2e 2e 20 61 5b 30 3a | 32 5d 20 3d 20 5b 5d 0d |... a[0:|2] = [].|
|00005de0| 3e 3e 3e 20 61 0d 5b 31 | 32 33 2c 20 31 32 33 34 |>>> a.[1|23, 1234|
|00005df0| 5d 0d 3e 3e 3e 20 23 20 | 49 6e 73 65 72 74 20 73 |].>>> # |Insert s|
|00005e00| 6f 6d 65 3a 0d 2e 2e 2e | 20 61 5b 31 3a 31 5d 20 |ome:....| a[1:1] |
|00005e10| 3d 20 5b 27 62 6c 65 74 | 63 68 27 2c 20 27 78 79 |= ['blet|ch', 'xy|
|00005e20| 7a 7a 79 27 5d 0d 3e 3e | 3e 20 61 0d 5b 31 32 33 |zzy'].>>|> a.[123|
|00005e30| 2c 20 27 62 6c 65 74 63 | 68 27 2c 20 27 78 79 7a |, 'bletc|h', 'xyz|
|00005e40| 7a 79 27 2c 20 31 32 33 | 34 5d 0d 3e 3e 3e 20 61 |zy', 123|4].>>> a|
|00005e50| 5b 3a 30 5d 20 3d 20 61 | 20 20 20 20 20 23 20 49 |[:0] = a| # I|
|00005e60| 6e 73 65 72 74 20 28 61 | 20 63 6f 70 79 20 6f 66 |nsert (a| copy of|
|00005e70| 29 20 69 74 73 65 6c 66 | 20 61 74 20 74 68 65 20 |) itself| at the |
|00005e80| 62 65 67 69 6e 6e 69 6e | 67 0d 3e 3e 3e 20 61 0d |beginnin|g.>>> a.|
|00005e90| 5b 31 32 33 2c 20 27 62 | 6c 65 74 63 68 27 2c 20 |[123, 'b|letch', |
|00005ea0| 27 78 79 7a 7a 79 27 2c | 20 31 32 33 34 2c 20 31 |'xyzzy',| 1234, 1|
|00005eb0| 32 33 2c 20 27 62 6c 65 | 74 63 68 27 2c 20 27 78 |23, 'ble|tch', 'x|
|00005ec0| 79 7a 7a 79 27 2c 20 31 | 32 33 34 5d 0d 3e 3e 3e |yzzy', 1|234].>>>|
|00005ed0| 20 0d 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d | .\end{v|erbatim}|
|00005ee0| 5c 65 63 6f 64 65 0d 25 | 0d 54 68 65 20 62 75 69 |\ecode.%|.The bui|
|00005ef0| 6c 74 2d 69 6e 20 66 75 | 6e 63 74 69 6f 6e 20 7b |lt-in fu|nction {|
|00005f00| 5c 74 74 20 6c 65 6e 28 | 29 7d 20 61 6c 73 6f 20 |\tt len(|)} also |
|00005f10| 61 70 70 6c 69 65 73 20 | 74 6f 20 6c 69 73 74 73 |applies |to lists|
|00005f20| 3a 0d 0d 5c 62 63 6f 64 | 65 5c 62 65 67 69 6e 7b |:..\bcod|e\begin{|
|00005f30| 76 65 72 62 61 74 69 6d | 7d 0d 3e 3e 3e 20 6c 65 |verbatim|}.>>> le|
|00005f40| 6e 28 61 29 0d 38 0d 3e | 3e 3e 20 0d 5c 65 6e 64 |n(a).8.>|>> .\end|
|00005f50| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|00005f60| 0d 25 0d 49 74 20 69 73 | 20 70 6f 73 73 69 62 6c |.%.It is| possibl|
|00005f70| 65 20 74 6f 20 6e 65 73 | 74 20 6c 69 73 74 73 20 |e to nes|t lists |
|00005f80| 28 63 72 65 61 74 65 20 | 6c 69 73 74 73 20 63 6f |(create |lists co|
|00005f90| 6e 74 61 69 6e 69 6e 67 | 20 6f 74 68 65 72 20 6c |ntaining| other l|
|00005fa0| 69 73 74 73 29 2c 0d 66 | 6f 72 20 65 78 61 6d 70 |ists),.f|or examp|
|00005fb0| 6c 65 3a 0d 0d 5c 62 63 | 6f 64 65 5c 62 65 67 69 |le:..\bc|ode\begi|
|00005fc0| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0d 3e 3e 3e 20 |n{verbat|im}.>>> |
|00005fd0| 71 20 3d 20 5b 32 2c 20 | 33 5d 0d 3e 3e 3e 20 70 |q = [2, |3].>>> p|
|00005fe0| 20 3d 20 5b 31 2c 20 71 | 2c 20 34 5d 0d 3e 3e 3e | = [1, q|, 4].>>>|
|00005ff0| 20 6c 65 6e 28 70 29 0d | 33 0d 3e 3e 3e 20 70 5b | len(p).|3.>>> p[|
|00006000| 31 5d 0d 5b 32 2c 20 33 | 5d 0d 3e 3e 3e 20 70 5b |1].[2, 3|].>>> p[|
|00006010| 31 5d 5b 30 5d 0d 32 0d | 3e 3e 3e 20 70 5b 31 5d |1][0].2.|>>> p[1]|
|00006020| 2e 61 70 70 65 6e 64 28 | 27 78 74 72 61 27 29 20 |.append(|'xtra') |
|00006030| 20 20 20 20 23 20 53 65 | 65 20 73 65 63 74 69 6f | # Se|e sectio|
|00006040| 6e 20 35 2e 31 0d 3e 3e | 3e 20 70 0d 5b 31 2c 20 |n 5.1.>>|> p.[1, |
|00006050| 5b 32 2c 20 33 2c 20 27 | 78 74 72 61 27 5d 2c 20 |[2, 3, '|xtra'], |
|00006060| 34 5d 0d 3e 3e 3e 20 71 | 0d 5b 32 2c 20 33 2c 20 |4].>>> q|.[2, 3, |
|00006070| 27 78 74 72 61 27 5d 0d | 3e 3e 3e 0d 5c 65 6e 64 |'xtra'].|>>>.\end|
|00006080| 7b 76 65 72 62 61 74 69 | 6d 7d 5c 65 63 6f 64 65 |{verbati|m}\ecode|
|00006090| 0d 25 0d 4e 6f 74 65 20 | 74 68 61 74 20 69 6e 20 |.%.Note |that in |
|000060a0| 74 68 65 20 6c 61 73 74 | 20 65 78 61 6d 70 6c 65 |the last| example|
|000060b0| 2c 20 7b 5c 74 74 20 70 | 5b 31 5d 7d 20 61 6e 64 |, {\tt p|[1]} and|
|000060c0| 20 7b 5c 74 74 20 71 7d | 20 72 65 61 6c 6c 79 20 | {\tt q}| really |
|000060d0| 72 65 66 65 72 20 74 6f | 0d 74 68 65 20 73 61 6d |refer to|.the sam|
|000060e0| 65 20 6f 62 6a 65 63 74 | 21 20 20 57 65 27 6c 6c |e object|! We'll|
|000060f0| 20 63 6f 6d 65 20 62 61 | 63 6b 20 74 6f 20 7b 5c | come ba|ck to {\|
|00006100| 65 6d 20 6f 62 6a 65 63 | 74 20 73 65 6d 61 6e 74 |em objec|t semant|
|00006110| 69 63 73 7d 20 6c 61 74 | 65 72 2e 0d 0d 5c 73 65 |ics} lat|er...\se|
|00006120| 63 74 69 6f 6e 7b 46 69 | 72 73 74 20 53 74 65 70 |ction{Fi|rst Step|
|00006130| 73 20 54 6f 77 61 72 64 | 73 20 50 72 6f 67 72 61 |s Toward|s Progra|
|00006140| 6d 6d 69 6e 67 7d 0d 0d | 4f 66 20 63 6f 75 72 73 |mming}..|Of cours|
|00006150| 65 2c 20 77 65 20 63 61 | 6e 20 75 73 65 20 50 79 |e, we ca|n use Py|
|00006160| 74 68 6f 6e 20 66 6f 72 | 20 6d 6f 72 65 20 63 6f |thon for| more co|
|00006170| 6d 70 6c 69 63 61 74 65 | 64 20 74 61 73 6b 73 20 |mplicate|d tasks |
|00006180| 74 68 61 6e 20 61 64 64 | 69 6e 67 0d 74 77 6f 20 |than add|ing.two |
|00006190| 61 6e 64 20 74 77 6f 20 | 74 6f 67 65 74 68 65 72 |and two |together|
|000061a0| 2e 20 20 46 6f 72 20 69 | 6e 73 74 61 6e 63 65 2c |. For i|nstance,|
|000061b0| 20 77 65 20 63 61 6e 20 | 77 72 69 74 65 20 61 6e | we can |write an|
|000061c0| 20 69 6e 69 74 69 61 6c | 0d 73 75 62 73 65 71 75 | initial|.subsequ|
|000061d0| 65 6e 63 65 20 6f 66 20 | 74 68 65 20 7b 5c 65 6d |ence of |the {\em|
|000061e0| 20 46 69 62 6f 6e 61 63 | 63 69 7d 20 73 65 72 69 | Fibonac|ci} seri|
|000061f0| 65 73 20 61 73 20 66 6f | 6c 6c 6f 77 73 3a 0d 0d |es as fo|llows:..|
|00006200| 5c 62 63 6f 64 65 5c 62 | 65 67 69 6e 7b 76 65 72 |\bcode\b|egin{ver|
|00006210| 62 61 74 69 6d 7d 0d 3e | 3e 3e 20 23 20 46 69 62 |batim}.>|>> # Fib|
|00006220| 6f 6e 61 63 63 69 20 73 | 65 72 69 65 73 3a 0d 2e |onacci s|eries:..|
|00006230| 2e 2e 20 23 20 74 68 65 | 20 73 75 6d 20 6f 66 20 |.. # the| sum of |
|00006240| 74 77 6f 20 65 6c 65 6d | 65 6e 74 73 20 64 65 66 |two elem|ents def|
|00006250| 69 6e 65 73 20 74 68 65 | 20 6e 65 78 74 0d 2e 2e |ines the| next...|
|00006260| 2e 20 61 2c 20 62 20 3d | 20 30 2c 20 31 0d 3e 3e |. a, b =| 0, 1.>>|
|00006270| 3e 20 77 68 69 6c 65 20 | 62 20 3c 20 31 30 3a 0d |> while |b < 10:.|
|00006280| 2e 2e 2e 20 20 20 20 20 | 20 20 70 72 69 6e 74 20 |... | print |
|00006290| 62 0d 2e 2e 2e 20 20 20 | 20 20 20 20 61 2c 20 62 |b.... | a, b|
|000062a0| 20 3d 20 62 2c 20 61 2b | 62 0d 2e 2e 2e 20 0d 31 | = b, a+|b.... .1|
|000062b0| 0d 31 0d 32 0d 33 0d 35 | 0d 38 0d 3e 3e 3e 20 0d |.1.2.3.5|.8.>>> .|
|000062c0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|000062d0| 63 6f 64 65 0d 25 0d 54 | 68 69 73 20 65 78 61 6d |code.%.T|his exam|
|000062e0| 70 6c 65 20 69 6e 74 72 | 6f 64 75 63 65 73 20 73 |ple intr|oduces s|
|000062f0| 65 76 65 72 61 6c 20 6e | 65 77 20 66 65 61 74 75 |everal n|ew featu|
|00006300| 72 65 73 2e 0d 0d 5c 62 | 65 67 69 6e 7b 69 74 65 |res...\b|egin{ite|
|00006310| 6d 69 7a 65 7d 0d 0d 5c | 69 74 65 6d 0d 54 68 65 |mize}..\|item.The|
|00006320| 20 66 69 72 73 74 20 6c | 69 6e 65 20 63 6f 6e 74 | first l|ine cont|
|00006330| 61 69 6e 73 20 61 20 7b | 5c 65 6d 20 6d 75 6c 74 |ains a {|\em mult|
|00006340| 69 70 6c 65 20 61 73 73 | 69 67 6e 6d 65 6e 74 7d |iple ass|ignment}|
|00006350| 3a 20 74 68 65 20 76 61 | 72 69 61 62 6c 65 73 0d |: the va|riables.|
|00006360| 7b 5c 74 74 20 61 7d 20 | 61 6e 64 20 7b 5c 74 74 |{\tt a} |and {\tt|
|00006370| 20 62 7d 20 73 69 6d 75 | 6c 74 61 6e 65 6f 75 73 | b} simu|ltaneous|
|00006380| 6c 79 20 67 65 74 20 74 | 68 65 20 6e 65 77 20 76 |ly get t|he new v|
|00006390| 61 6c 75 65 73 20 30 20 | 61 6e 64 20 31 2e 20 20 |alues 0 |and 1. |
|000063a0| 4f 6e 20 74 68 65 0d 6c | 61 73 74 20 6c 69 6e 65 |On the.l|ast line|
|000063b0| 20 74 68 69 73 20 69 73 | 20 75 73 65 64 20 61 67 | this is| used ag|
|000063c0| 61 69 6e 2c 20 64 65 6d | 6f 6e 73 74 72 61 74 69 |ain, dem|onstrati|
|000063d0| 6e 67 20 74 68 61 74 20 | 74 68 65 20 65 78 70 72 |ng that |the expr|
|000063e0| 65 73 73 69 6f 6e 73 20 | 6f 6e 0d 74 68 65 20 72 |essions |on.the r|
|000063f0| 69 67 68 74 2d 68 61 6e | 64 20 73 69 64 65 20 61 |ight-han|d side a|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.