245x Filetype PDF File size 0.26 MB Source: ir.cwi.nl
Centrum voor Wiskunde en Informatica
REPORTRAPPORT
Python tutorial
G. van Rossum
Computer Science/Department of Algorithmics and Architecture
CS-R9526 1995
Report CS-R9526
ISSN 0169-118X
CWI
P.O. Box 94079
1090 GB Amsterdam
The Netherlands
CWI is the National Research Institute for Mathematics
and Computer Science. CWI is part of the Stichting
Mathematisch Centrum (SMC), the Dutch foundation
for promotion of mathematics and computer science
and their applications. Copyright © Stichting Mathematisch Centrum
SMC is sponsored by the Netherlands Organization for P.O. Box 94079, 1090 GB Amsterdam (NL)
Scientific Research (NWO). CWI is a member of Kruislaan 413, 1098 SJ Amsterdam (NL)
ERCIM, the European Research Consortium for Telephone +31 20 592 9333
Informatics and Mathematics. Telefax +31 20 592 4199
✁✄✂✆☎✞✝✆✟✡✠☞☛✍✌✎☎✏✟✒✑✔✓✖✕✘✗
✙✛✚✢✜ ✣✥✤✧✦✩★✏✪✬✫✭✤✥✮✯✮✰✚✲✱
✳✵✴✡✶
✷✹✸✻✺✞✸✲✼✾✽❀✿❂❁❄❃❆❅✹❇❈❁❄❉✲❊✰❅✩❁❋❅❍●■✼✄❏✞❑▼▲❄◆✻❖✯P❘◗✰❙❈❑❍❉✥❚✲❯✰❖▼❱✵❖✔◆✻❯✰❖✯P❳❲ ❙❈❨✰◗✰▲
❩✹❬✞❭✥❪■❫✏❴✏❵✲❛✾❭❝❜✖❞✞❡
❢■❣✐❤❦❥♠❧ ♥✩♦❝♣❆q r❍st♣❈✉❍✈✞✇❈❤❘❧ ①✹♣❈②✔②✰③✩④
⑤⑦⑥✛⑧✰⑨❆⑩✹❶✵❷❸⑨
❹✥❺❄❻❽❼❋♥✩♦✆❧ ❥■❾✆❥♠❧ ❿▼✇✰① ❣✐➀✯❺♠❣❄❻✭✇✰♥❈➁■❣❈❤➃➂✖➄✰①✰✇❈❤❦♥❈➅✢❤❦❾✰❿❍❿▼❧ ♦✯➅➆① ❾✰♦✯➅✹➄❈❾✯➅✩❣✞❻❽❼❈❾❈❻■➇❈❤❳❧ ➈❈➅✩❣✯❥■❻❽❼❈❣✭➅❆❾❋✇❝➇✰❣✯❻❳➁➉❣❄❣✐♦✆➊➋❾✰♦❈➈❝❥➌❼❈❣❈① ①❈✇❈❤❦♥❈➅✢❤❦❾✰❿❍❿▼❧ ♦✯➅✢➀
❾❋♦❋➈✒❧ ❥■❻❽❼✰➄❋❥➍❧ ➈✰❣❄❾✰① ① ❺✞❥♠➄✰❧ ❻✖❣❄➈➎➂❳♥✰❤✞➏t❻❽❼✰❤❦♥❈➁■➐✖❾✯➁■❾❄❺✆✇✐❤❦♥❈➅✹❤✻❾✰❿▼❿❍❧ ♦✯➅✰➑➒❾✰♦❈➈✘❤❦❾✰✇✰❧ ➈▼✇✐❤❦♥✰❻➓♥✰❻❘❺✐✇✰❧ ♦✯➅✥q✭➔ ❻✖❥✭❥❽❺❈♦❈❻✖❾✯→➎❧ ❥➍✇✔➄❈❻■❻✖♥❈➅❆❣❄❻❽❼❈❣❈❤❆➂✖❤✻♥❆❿
➣ ♥✩♦❈❥t❻❽❤❘➄ ➣ ❻✖❥✵➇✔♥❋❤❘❤❦♥❈➁■❣❄➈❝➂↔❤❦♥✩❿↕❾▼➙❄❾✐❤❘❧ ❣❄❻❘❺✆♥❈➂■♥✰❻❽❼❈❣❈❤■① ❾❋♦✐➅✢➄❈❾✯➅✩❣❄❥♠➛❆❿✛♥✰❥t❻✵✇❈❤❦♥✩❿▼❧ ♦❈❣❈♦❈❻✏❾✐❤❦❣❍❧ ♦✯➜✥➄❈❣✐♦ ➣ ❣❄❥➉➂↔❤❦♥✩❿↕✈➒➝■➊■➀❆➊■➀✏➞▼♥✩➈❆➄✰① ❾✯➐✖➟
❾❋♦❋➈➋➔ ➣ ♥✩♦❆q
➠✞❼❈❣✆❹✥❺❄❻t❼❈♥✩♦✆❧ ♦❋❻✖❣✐❤❘✇❈❤❦❣❄❻✖❣❈❤✹❧ ❥✏❣❄❾❈❥♠❧ ① ❺■❣❀→✐❻✖❣❈♦❈➈✰❣❄➈✆➁✞❧ ❻t❼➒♦❈❣✯➁➋➂↔➄✰♦ ➣ ❻❽❧ ♥✩♦❈❥✏❾✰♦❈➈✆➈✰❾❈❻✖❾➒❻❘❺❈✇✰❣✯❥✾❧ ❿▼✇✰① ❣❈❿✛❣❈♦❈❻✖❣♠➈➒❧ ♦➒➊✭q❆❹✥❺✯❻❽❼❈♥✩♦✎❧ ❥✏❾✰① ❥t♥
❥➌➄✰❧ ❻✖❾✰➇✰① ❣➒❾❈❥✞❾✰♦▼❣♠→❈❻✖❣✐♦❈❥♠❧ ♥✩♦✛① ❾❋♦✐➅✢➄❈❾✯➅✩❣✎➂❳♥✰❤■❼✰❧ ➅✢❼✰① ❺ ➣ ➄❈❥t❻✖♥✩❿▼❧ ➡♠❾❋➇✔① ❣✞➊➢❾✰✇✰✇✰① ❧ ➣ ❾✐❻t❧ ♥✩♦❋❥■❥➌➄ ➣ ❼❝❾✐❥✞❣✯➈✩❧ ❻✖♥✰❤✻❥✭♥✰❤■➁✞❧ ♦❈➈✰♥❈➁✬❿✛❾✰♦❈❾✯➅✩❣❈❤❦❥❄q
❹✥❺✯❻❽❼❈♥✩♦✆❧ ❥➤❾❈➙✯❾❋❧ ① ❾❋➇✔① ❣➉➂❳♥✰❤✹➙✯❾✐❤❘❧ ♥✩➄❈❥✏♥✩✇✔❣✐❤❦❾❈❻❽❧ ♦✐➅➆❥t❺❄❥t❻✖❣✐❿❝❥➌➀✯❾✰❿❝♥✩♦✯➅✩❥t❻✹➁➍❼✔❧ ➣ ❼➒❥t❣❄➙✯❣✐❤❦❾✰①❀➜✢❾❈➙❄♥✰❤❦❥✏♥❈➂■➥✭➦✞➔ ➧➍➀❈✈✞❿❝♥✩❣❈➇❈❾✰➀❈❻❽❼❈❣✞✈✞✇✰✇✰① ❣
➞❍❾ ➣ ❧ ♦❈❻✖♥✰❥♠❼✛➨➎q ➩✲q ➀✹❾✰♦❈➈➋➞✒➩✔➐♠➫✵➨✎➩✲q
➠✞❼✰❧ ❥❝❻❽➄❈❻✖♥✰❤❘❧ ❾✰①✏❧ ♦❈❻❽❤❦♥✩➈❆➄ ➣ ❣✯❥➆❻t❼❈❣✡❤❦❣❄❾❈➈✰❣❈❤➒❧ ♦✯➂❳♥✰❤❘❿❝❾❋① ① ❺✛❻✖♥➋❻❽❼❈❣➋➇❈❾❈❥➌❧ ➣❍➣ ♥✩♦ ➣ ❣✐✇❈❻✖❥❝❾❋♦❋➈➋➂❳❣✯❾✐❻t➄✰❤❦❣❄❥✆♥❈➂➒❻❽❼❈❣➭❹✥❺❄❻t❼❈♥✩♦➋① ❾✰♦✯➅✹➄❈❾✯➅✩❣
❾❋♦❋➈✄❥❽❺✯❥❽❻➓❣✐❿➯q✄➔ ❻❍❼❈❣❈① ✇❈❥❝❻✖♥✄❼❈❾❈➙❄❣❂❾➢❹✥❺✯❻❽❼❈♥✩♦➭❧ ♦❈❻➓❣✐❤❘✇❈❤✻❣✯❻✖❣✐❤✞❼❋❾❋♦❋➈✰❺➲➂❳♥✰❤➒❼❈❾✰♦❈➈✔❥✖➐✖♥✩♦➋❣❀→❋✇✔❣✐❤❘❧ ❣✐♦ ➣ ❣✐➀✭➇✰➄❈❻✛❾❈❥▼❻❽❼❈❣✘❣♠→❈❾✰❿❍✇✰① ❣❄❥✆❾❈❤✻❣
❥❽❣❈① ➂❦➐ ➣ ♥✩♦❈❻✖❾✰❧ ♦❈❣❄➈❆➀❈❻❽❼❈❣✛❻t➄❈❻✖♥✰❤❘❧ ❾✰① ➣ ❾✰♦❍➇✔❣❍❤❦❣❄❾❈➈✘♥❈➳✲➐❽① ❧ ♦❈❣✞❾❈❥✞➁■❣✐① ①➵q
➸❈♥❋❤❝❾✄➈✰❣✯❥ ➣ ❤❘❧ ✇❈❻t❧ ♥✩♦➺♥❈➂✛❥❽❻✖❾✰♦❈➈✔❾✐❤❦➈➻♥❆➇t➼❳❣ ➣ ❻✖❥✘❾✰♦❈➈✬❿❝♥❆➈✩➄✰① ❣❄❥♠➀✭❥❽❣✯❣❂❻❽❼❈❣➾➽➒➚✹➪✻➶✏➹❆➘✍➴✭➷↔➬❋➮➌➱❆➮✯➚❐✃✆❒✖❮❈❒❈➮♠❒❈➘■❰❄❒✘❿✛❾✰♦✰➄❋❾❋①➵qÏ➠➍❼❈❣
➽➒➚✹➪✻➶✏➹❆➘➻✃✆❒✖❮❈❒❈➮♠❒❈➘■❰❄❒❝ÐÑ➱❆➘✏Ò➤➱❆Ó❈➅✹❧ ➙✯❣❄❥✞❾❍❿❝♥✰❤✻❣✎➂❘♥❋❤❘❿❝❾✰①❈➈✰❣♠Ô✥♦✰❧ ❻❽❧ ♥✩♦✛♥❋➂✾❻t❼❈❣✛① ❾✰♦✯➅✢➄❋❾❄➅❆❣✰q
â Õ ✃×Ö✏Ò➤➬➓Ø✐❒✯❰✰➪ Õ Ó✻➱❆Ù✯Ù❄➷ Ú✆❰❄➱✹➪❘➷✖➹❆➘✄Û❄Ü✹Ý✹Ý✹Ü❈Þ❆ß✞➫✞q ➟✹q r❆➀✏➫✞q ➟✹q ➟✩➀✾➫✞q ♣❆q ③✩➀✲à✲q ♣✰➀➉➫✞q r✹q á✩➀✏➫✞q r❸q ❿✘q
❒❈➚❆ã➒➹❆➮♠ä❆Ù➯åæ➽✞➶✲➮➌➱❆Ù❈❒❈Ù✐ß✭➨➒➇t➼❘❣ ➣ ❻❘➐✖♥✰❤❳❧ ❣✐♦❋❻✖❣❄➈❍① ❾✰♦✯➅✢➄❈❾✯➅✩❣✯❥➌➀✲❹✲❺❄❻❽❼❈♥❆♦✰➀✥➩✹✇❈❾✰♦✰❧ ❥♠❼✘➔ ♦❈ç❆➄✰❧ ❥♠❧ ❻❽❧ ♥❆♦✰➀✩➩✲❹✰✈✎➞❂q
òôó✩õ✲õ■ó❋ö❋ó❆õ✥õ✥÷➺ø
è▼é✥ê✏ë✏ì♠í❘î✥ï✏ð×ñ ëÏù✏ð♠í ñ ï➤ð❀í❳ú■îÏûÏü✥ð✯ï■ý✰þ⑦ü✲ð♠í❳ÿ ñ ï è▼ý✰ú✏ð❄ì ✁ þ ✂ ✄➲þ⑦ÿ❄ð❄ý✔ì✆☎■ü✲þ ✂✞✝ ï■ý✠✟✘ý✔ð❄ï■ý✰ì☛✡❳ü✲ú☞☎■ÿ✍✌
✄✎✡✏✡✒✑✒í❳î✥ï✏ð✯ÿ✓✑✘ý✰ÿ✯ý✰ì✆✔✲ý✍☎
✕ ý✰ì❄þ➢í❘ÿ❄ÿ❀í❳é✥ú ð✯é ✁ ÿ❄ý ✂ ñ é✥ê✏ë ✂ þ⑦é✖☎✏í✏✗❽ë ✂ ü✥ú☞☎✘☎✏í❘ÿ❄ð✯ì♠í ø ✁ ð❄ý✧ð❄ï✏í❘ÿ✡ÿ✯é✙✗❽ð✛✚▼ü✥ì✯ý✄ü✥ú✜☎✬í❘ð❄ÿ✢☎■é ñ ✁ þ⑦ý✔ú➤ð✯ü✥ð❀í❳é✥ú✣✗❽é✲ì✘ü✥ú✏ëÏê ✁ ì❄ê✭é✥ÿ✯ý
ü✥ú✜☎✤✚▼í❘ð❄ï■é ✁ ð✎✗tý✰ý➋í❳ÿ➲ï■ý✰ì✯ý ø ë❐î✲ì❄ü✲ú➤ð✯ý✍☎ ✂ ê■ì❄é✙✔✲í✥☎➉ý✍☎✍ð❄ï➉ü✥ð✘ð❄ï➉ý✄ü ø é✙✔✥ý ñ é✲ê➤ë✏ì❀í❳î✥ï✏ð➲ú■é✥ð❀í ñ ý➢ü✥ê■ê✭ý✰ü✲ì▼í❳ú✍ü✦✡✧✡ ñ é✥ê✏í❘ý✰ÿ➋ü✥ú☞☎
ð❄ï➉ü✥ð ø é✥ð❄ïÏð✯ï■ü✥ð ñ é✲ê✏ë➤ì❀í❳î✲ï➤ð✘ú➉é✥ð♠í ñ ý✄ü✲ú☞☎Ïð❄ï✏í❘ÿ❂ê✭ý✰ì❄þ➢í❘ÿ❄ÿ♠í❘é✥ú ú■é✥ð❀í ñ ý➭ü✥ê■ê✭ý✰ü✥ì▼í❘ú✍ÿ ✁ ê■ê✵é✲ì❄ð❀í❳ú■î★☎■é ñ ✁ þ⑦ý✰ú✏ð❄ü✲ð♠í❘é✥ú ✂ ü✥ú☞☎
ð❄ï➉ü✥ð➋ð❄ï■ý➢ú■ü✲þ⑦ý✰ÿ➋é✙✗✒ù✏ð❀í ñ ï✏ð♠í❘ú■î ûÏü✲ð❄ï■ý✰þ⑦ü✲ð♠í❘ÿ ñ ï è▼ý✰ú✏ð❄ì ✁ þ é✲ì➺è✪✩✬✫✘ú■é✥ð ø ý ✁ ÿ✯ý✍☎↕í❳ú ü✭☎✜✔✥ý✰ì✯ð♠í❳ÿ❀í❳ú■î↕é✥ì➋ê ✁ ø ✡❦í ñ í❘ð♠ë
ê✭ý✰ì❄ð✯ü✹í❳ú✾í❳ú■îÏð❄é✮☎✏í❘ÿ❄ð❄ì❀í ø ✁ ð♠í❳é✲ú é✙✗✆ð❄ï■ý➋ÿ❄é✦✗❽ð✛✚▼ü✥ì❄ý✢✚▼í❘ð❄ï■é ✁ ð❂ÿ✯ê✵ý ñ í✧✯ ñ ✂ ✚✘ì♠í❳ð✯ð❄ý✰ú↕ê■ì♠í❘é✥ì❂ê✭ý✰ì✯þ➢í❳ÿ❄ÿ❀í❳é✲ú✰✌
ù ✝ ✫❄è✎✱ ✝ ✫✆✟✓✲ û✘✄ ✝ ✱✓✳❝û✘✄ ✝ ✫❄ù■è✎✱ è✎✳✴✟ ✝ ✑✎✵❂û✷✶✸✫❄ù■è✎✹✺✄✓✫❄û✍ù✣✄✻✹✼✹✽✩✾✄✢✑✓✑✎✄✢✟ ✝ ✫✆✳✛ù✣✩✿✫ ✝ ✱❀✑✸✳❁✲✢✄✢✑✓✶
✝✓❂❃✝ ✱✎✫❄ù ù ❂✻❄✼✝ ✩✾✄✢✑✓✳ ✂ ✫✆✟❂è✎✹✼✵✓✶✸✫✆✟✓✲❅✄✢✹❆✹✽✫❄û ✕ ✹✰✫✆✳❁✶❃✩✾✄✢✑✓✑✎✄✢✟ ✝ ✫✆✳✛ù ❂✢❄ û✾✳✴✑✘è✎✱✎✄✻✟ ✝ ✄✻❇✴✫✆✹✰✫ ✝✪❈
✄✻✟✸✶ ❄ ✫ ✝ ✟✓✳✛ù■ù ✂ ✫✆✟❉✟ ❂ ✳✒❊✻✳❁✟ ✝ ù☞✱❋✄✻✹✼✹ ù ✝ ✫❄è✎✱ ✝ ✫✆✟✓✲☞û✘✄ ✝ ✱✸✳✛û✘✄ ✝ ✫❄ù➉è✎✱ è✎✳❁✟ ✝ ✑✎✵❂û●❇❍✳✽✹✰✫✛✄✢❇❍✹✼✳ ö
❄❆❂ ✑■✄✢✟ ❈ ù ✕ ✳✛è✪✫✛✄✻✹ ✂ ✫✆✟✸✶✓✫✆✑✸✳✛è ✝❏❂ ✑ è ❂ ✟➲ù☞✳❁❑✢✵✓✳❁✟ ✝ ✫✛✄✻✹✘✶✎✄➋û✘✄✓✲✠✳✛ù ❂ ✑❏✄✻✟ ❈ ✶✎✄➋û✘✄✓✲✠✳✛ù✸✩▲✱❋✄ ✝
ù ❂ ✳▼❊✢✳❁✑▲✑✸✳✛ù☞✵✸✹ ✝ ✫✆✟✓✲ ❄ ✑ ❂ û◆✹ ❂ ù➉ù ❂✢❄ ✵➲ù☞✳ ✂ ✶✎✄ ✝ ✄ ❂ ✑ ✕ ✑ ❂✢❄ ✫ ✝ ù ✂ ✩▲✱✸✳ ✝ ✱✓✳✴✑✿✫✆✟✬✄✻✟✬✄❂è ✝ ✫ ❂ ✟
❂✢❄ è ❂ ✟ ✝ ✑❋✄❂è ✝✢✂ ✟✓✳❁✲❖✹✰✫✆✲✠✳❁✟➲è✎✳ ❂ ✑ ❂✸✝ ✱✓✳❁✑ ✝✓❂ ✑ ✝ ✫ ❂ ✵❂ù✣✄❂è ✝ ✫ ❂ ✟ ✂ ✄✢✑✎✫❄ù✖✫✆✟✸✲ ❂ ✵ ✝P❂✢❄▲❂ ✑◗✫✆✟
è ❂ ✟✓✟✸✳✛è ✝ ✫ ❂ ✟❘✩✿✫ ✝ ✱ ✝ ✱✸✳❙✵➲ù☞✳ ❂ ✑ ✕ ✳❁✑ ❄✼❂ ✑❂û✘✄✢✟❂è✎✳ ❂✢❄❏✝ ✱✎✫❄ùÏù ❂✢❄✼✝ ✩✾✄✢✑✓✳✪✌
Contents
1 WhettingYourAppetite 1
1.1 WhereFromHere ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 2
2 UsingthePythonInterpreter 3
2.1 Invoking the Interpreter ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 3
2.1.1 ArgumentPassing ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 4
2.1.2 Interactive Mode ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 4
2.2 TheInterpreter and its Environment ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 4
2.2.1 Error Handling ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 4
2.2.2 TheModuleSearchPath ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 5
2.2.3 “Compiled”Pythonfiles ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 5
2.2.4 Executable Python scripts ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 5
2.2.5 TheInteractive Startup File ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 5
2.3 Interactive Input Editing and History Substitution ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 6
2.3.1 Line Editing ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 6
2.3.2 History Substitution ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 6
2.3.3 KeyBindings ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 6
2.3.4 Commentary ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 7
3 AnInformalIntroductionto Python 8
3.1 Using Pythonas a Calculator ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 8
3.1.1 Numbers ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 8
3.1.2 Strings ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 10
3.1.3 Lists ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 12
3.2 First Steps Towards Programming ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 14
4 MoreControl FlowTools 16
4.1 If Statements ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 16
4.2 For Statements ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 16
4.3 Therange()Function ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 17
4.4 Breakand Continue Statements, and Else Clauses on Loops ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 18
4.5 Pass Statements ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 18
4.6 DefiningFunctions ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 19
5 OddsandEnds 21
5.1 MoreonLists ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 21
5.2 Thedelstatement ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ ❚ 22
i
no reviews yet
Please Login to review.