[PDF] [PDF] Learning to Program Using Python - Home Page do Professor

it can be used to tie large projects together or for rapid prototyping It has a built- in GUI copies of the PDF are available at this book's website: http://python- of information there and regex is a little too advanced for this book; there are books  



Previous PDF Next PDF





[PDF] Python Projects - Programmer Books

In the final chapters, we'll show more advanced topics in Python, such as how to To work through the examples and projects in this book, you will also need 



[PDF] Expert Python ProgrammingPdf

In other words this book describes how an advanced Python developer works Chapter 8 gives some insight on how a project code base can be managed and



[PDF] A Python Book: Beginning Python, Advanced Python, and Python

15 déc 2013 · 2 1аааIntroductionаннаPython 201анна(Slightly) Advanced Python Topics PDFаннаhttp://www davekuhlman /python_book_01 pdf http:// python net/~goodger/projects/pycon/2007/idiomatic/handout html



[PDF] Mastering Python Programming (with Advanced Topics)

Course: TTPS4820 Mastering Python Programming (with Advanced Topics) with comprehensive machine-based practical programming labs and project work



[PDF] Exper Python Programmingpdf

In other words, this book describes how an advanced Python developer works every day technical writing and how Python projects should be documented



[PDF] Programming with Python - MEDIASAPIENS

For example, Python is a very lean programming language Python programs are a Sync's advanced security measures mean you're never vulnerable can incorporate existing libraries into their projects and only need to develop the new  



[PDF] Python 3 for Absolute Beginnerspdf - Pirate

project and write your code in a way that makes it easy for someone else to Land once you have had time to study these more advanced incantations



[PDF] Python Basics: A Practical Introduction to Python 3 - Real Python

bers of the Real Python tutorial team who worked on Python Basics: David Amos is the selling programming book for intermediate Python developers Joanna Jablonski is the 18 3 Challenge: PDF Page Extraction Application 543



[PDF] Learning to Program Using Python - Home Page do Professor

it can be used to tie large projects together or for rapid prototyping It has a built- in GUI copies of the PDF are available at this book's website: http://python- of information there and regex is a little too advanced for this book; there are books  

[PDF] advanced python scripting for arcgis pro

[PDF] advanced r packages

[PDF] advanced real analysis book pdf

[PDF] advanced real analysis textbook pdf

[PDF] advanced regular expression in python

[PDF] advanced research methodology pdf

[PDF] advanced search app for android

[PDF] advanced segmentation adobe analytics

[PDF] advanced setting app for android

[PDF] advanced shell scripting pdf

[PDF] advanced spoken english lessons pdf

[PDF] advanced sql book reddit

[PDF] advanced sql books

[PDF] advanced sql books free download

[PDF] advanced sql commands with examples pdf

LearningtoProgramUsi ngPython

CodyJacks on

2

Copyright©2009-2013CodyJackson.

Thisworkis licensedunde rtheCr eativeCommons

license,visithttp://creativecommons.org/lic enses/ by-sa/3.0/orsend ale ttertoCreativeCommon s,444 CastroStreet,Suite900 ,

MountainView,California,9 4041,USA.

Thesour cecodewithinthiste xtislicensed undertheGNUGen eral PublicLicense(GPL) .Thefollowinglicensein formationcoversal l codecontaine dherein,exceptthosethatexp licitlystateotherwise : Copyright©2006-2011CodyJackson.Thispro gramisfr ee software:youcanredistri buteitand/ormo difyi tunderthetermsof theGNUGene ralPu blicLicenseaspublis hedbytheFreeS oftware Foundation,eitherversion3ofthe License,or(atyouro ption)any laterversion . Thisprogr amisdistributedintheh opeth atitwillbeuseful,but WITHOUTANYWARRAN TY;withoute ventheimpliedwarranty ofMERC HANTABILITYorFITNESSFORAPARTICULAR PURPOSE.SeetheGNUGener alPubl icLicensefo rmoredetail s. Youshou ldhavereceivedaco pyoftheGNUGe neralPublicLicense alongwiththispr ogram.Ifno t,seehttp:/ /www.gnu.org/licenses/.

Contents

ITheCoreLanguage1

1Int roduction3

1.1Why Python?.. ............ .. ... ... .4

1.2Why AnotherTu torial?........ ......... .5

1.3Getting Python... ......... ... .. ... ..6

1.4Convent ionsUsedinthisBook........... ...7

2Ho wisPython Di

erent?9

2.1Pytho nConcepts.......... ............9

2.1.1Dyn amicvs.StaticTyp es.. ...... .....9

2.1.2Interprete dvs.Compiled.............10

2.1.3Protot yping............ .. ... ... .11

2.1.4Pro ceduralvs.Object-OrientedProgramming..12

3Co mparingProgrammingLanguages 13

3.1C. ... .. ... ... ... ... ... ... ... ... .14

3.2C++.... ...... ... .. ... ... ... ... ..1 5

3.3Jav a........ ... ... ... .. ... ... ... .16

3.4C#.... ... ... ... ... ... .. ... ... ... 18

3.5Pyth on....... ... ... ... ... ... .. ... 22

4Th ePythonInt erpreter25

4.1Laun chingthePythoninterpreter...... ..... ..25

4.1.1Wind ows............ ... .. ... ..26

4.1.2Mac ...... ... ... ... .. ... ... ..26

4.2Pyth onVersions.... ......... ... ... ... 27

i iiCONTENTS

4.3Usingt hePythonCommand Prompt... ........28

4.4Comment ingPython................. ...29

4.5Laun chingPythonprograms......... .......29

4.6Integra tedDevelopmentEnvironments ..........30

5Ty pesandOperato rs33

5.1Pyth onSyntax.... ......... ... ... ... .33

5.1.1Indentation .....................33

5.1.2M ultipleLineSpanning ......... .....35

5.2Pyth onObjectTypes.. ........ ......... 35

5.3Pyth onNumbers... ............ ... ... .37

6Strings39

6.1Basicstrin goperation s..... ........ ... ... 40

6.2Indexin gandslicingstrings.. ......... .....42

6.3Strin gFormatting.... ......... ... ... .. 43

6.4Combini ngandSeparatingStrings. ......... ..45

6.5Regular Expressions. ............ ... ... .47

7Lists49

7.1Listu sage.. ..... ... ... ... ... ... ... .50

7.2Ad dingListElements........ ... ........ 51

7.3Mu tability........... ... ... ... ... ... 54

7.4Meth ods............ ... .. ... ... ... .54

8D ictionaries57

8.1Makin gadictiona ry.. ..................58

8.2Basicop erations. ......... ... ... .. ... .59

8.3Dictionary details.... ...... .. ... ... ... .61

8.4Operation ...... ... ... .. ... ... ... ... 61

9Tu ples63

9.1Why UseTuples? ...... ........... ... ..64

9.2S equenceUnpacking.... .............. ..65

9.3Meth ods............ ... .. ... ... ... .66

CONTENTSiii

10Files 69

10.1File Operations ......... ... ... .. ... ... 70

10.2Filesan dStreams ...... ..... ... ... ... ..70

10.3Creatinga File................ ... ....71

10.4Readin gFromaFile.... ...... .. ... ... ..72

10.5Iterating ThroughFiles............ ......75

10.6Seekin g........ ... ... .. ... ... ... ..76

10.7S erialization..... ... ... ... ... .. ... ... 77

11Stat ements79

11.1Assignmen t........ ... ... .. ... ... ... 80

11.2Express ions/Calls......................82

11.3Prin ting.......... ... .. ... ... ... ... 82

11.4ifTests........ ... ... ... ... .. ... ..8 3

11.5whileLoops...... ... ... ... ... ... .. ..85

11.6forLoops...... ... ... ... ... .. ... ... 86

11.7passStatement.......... ... ... .. ... ..8 8

11.8breakandcontinueStatements........... ... 89

11.10importandfromStatements............ ... .89

11.11defandreturnStatements............ ... ..8 9

11.12ClassStatements....... ...............90

12Docum entingYourCode91

13Maki ngaProgram99

13.1Makin gPythonDoSomething ......... .. ...100

13.2Scop e........ ... ... .. ... ... ... ... 103

13.3Defau ltArguments..... ......... .. ... ..104

14Except ions107

14.1Exceptio nClassHierarchy............ ....110

14.2User-Defin edExceptions... ............ ..112

15Object OrientedProgr amming115

15.1Learning PythonClasses........... .......115

15.2HowAreCl assesBett er?...... ............116

15.3Improvin gYourClassStanding...... ........116

ivCONTENTS

15.4SoWhatDo esaClas sLookLike?. ...........1 18

15.5"New-styl e"classes.................... .120

15.6ANote Abou tSt yle........ ......... .. .121

16More OOP123

16.1Inherita nce.........................1 23

16.2Operator Overloads... ......... .. ... ... 125

16.3ClassMeth ods........ ...............127

16.4Hav eyouseenmyclass?.. ...... .. ...... ..128

17Data bases131

17.1How toUseaDatabase. ... ... ... ..... ... 132

17.2Workin gWithaDatabase.... ... ... ..... .132

17.3Using SQLtoQuerya Database.... ... ..... .133

17.4Pyth onandSQLite.... ...... ..... ... ... 135

17.5Creating anSQLiteDB........... ..... ..135

17.6Pu llingDatafromaDB.... ... ...... ... .. 137

17.7SQLite DatabaseFiles... ...... .. ... ... ..140

18Distri butingYourProgram143

19Python3 145

IIGraph icalUserInterfaces(GUIs) 147

20Grap hicalUserInterfaces149

20.1Introduct ion.........................149

20.2Pop ularGUIFrameworks...... ... ........ 150

20.3Before YouStart.. ...... ..... ... ... ... 152

21ASim ple GraphicalDiceRoller1 55

22WhatC anwxPython Do?163

IIIWebPro gramming& GameDevelopment167

23Develo pingfortheWeb169

CONTENTSv

23.1ChooseYou rPoison....... ............ .169

23.2KarrigellW ebFramew ork..... ........ ... .170

23.2.1Pyth onScripts.... ........... ... .172

23.2.2KarrigellS ervic es............. ... ..172

23.2.3PythonInsideH TML............... 173

23.2.4HTMLInsidePyt hon...... .........173

23.2.5HTMLTags..... ................174

23.2.6T emplateengineintegration.. ......... .175

23.2.7KarrigellT emplates. ......... .. ... .175

23.3What'sIn cluded?........... ...........177

24Game Development179

24.1PyGame ...... ... ... ... ... .. ... ... .179

24.1.1GameDevelop mentwithPyGam e........180

24.1.2PyGame Limitations.... ...... .. ... .180

24.2Parts ofaVideoGame ...... ... ...... .. ..181

24.2.1GameE ngine ............ .. ... ... 181

24.2.2Input........ ........... ... ..1 81

24.2.3Graph ics........ ... ... ... .. ... 181

24.2.4Aud io........ ... ... .. ... ... ..182

24.2.5UserInterface ........... .........182

24.3AS ampleGame ......... ... .. ... ... ..182

24.4PyGame Modules ............... ... ... .184

ASt ringMethods189

BLi stMethods195

CDi ctionaryoperations197

DOp erators201

ESampleprograms203

E.1Dice rollingsimul ator.............. .....203

E.2Tempera tureconversion........... .......207

E.3Game characteratt ributegenerator....... .....208 E.4Text -basedcharactercreation. ..............211

FGN UGeneralP ublicLicense233

viCONTENTS PartI

TheCoreL anguage

1

Chapter1

Introduction

putergame.Ihad takenseveralpr ogr ammingcla ssesincollege( C, C++,andJav a)butnoth ingreallyserio us.I'mnota ComputerSci- encemajor andIdon'tprogr amona professional level. Idi dn'treallylikethel ow-levelworkinvolv edwithC/C++.Thi ngs likepointers ,memorymanagement,andothercon ceptsw eredi cult formetog rasp, muchless e ectivelyuse.Java,asmyfirst pro- grammingclassinsc hool,didn 'tmake anysense.Ihadneveru sed anobj ect-orientedlanguagebeforeandobj ect-orientedprogramming (OOP)conceptsg avemefits.Itprobablydidn' thelpthatmyJ ava classwasn't actuallyrealJav a;itwasactuallyMicr osoft's"custom" version:J++.Sonotonlyw asIlearning alangu agethatha dlittle practicaluse(J++addedandcutm any featuresfoundinrealJ ava), butthe programs didn'tworkcorrectly.Ult imatelythecla sswascan- celedneartheend ofthe semesterandevery onerecei ve dfullcredit . Theseproblems ,andissueslearningotherpro grammingl anguages, leftabadtastein mymou thforprogramming. Ineve rtho ughtI learnedalanguagewell enou ghtofeelcomfortab leusingit,muc hless actuallyenjoy programming.ButthenIheardabou tPythonona computerforum,andnot icedseveralot herment ionsofthelanguage atothe rsitesaroundthe Internet.People weretalkingabouth ow greatthe languagewas forpersonalp rojectsandhow versatileitis.I decidedtogi veprog rammingonemoretry andseeifPythonwasthe 3

4CHAPTER1.INTRODUCTION

languageforme. Tog ivememoreinc entive tolearnthel anguage,Idecidedtorecre- atearole pla yinggame frommychildhoodas acompu tergame.Not onlywould Ihaveareasontolearn thelan guagebut,hopefully, Iw ould havesomethingusefult hatIcouldgivet oot hersfortheirenjoy ment.

1.1WhyPyt hon?

Pythonisregardeda sbeingag reathobbyistlanguage, yetitis alsoan extremelypowerfullanguage. IthasbindingsforC/C++andJa vaso itcan beused totielargeproj ectstogetherorforrap idprotot yping. Itha sabuilt- inG UI(graphicaluserinterfa ce)librar yviaTkinter, whichletsthep rogrammermak esimpleg raphicalinterfaceswithlittle e ort.However, other,morepowerfulandcompleteGUI buildersare available,suchasQtandGTK+.IronP ython,aPytho nvers ionfor Windowsusingthe.NET framework,isal soavailab leforthoseu sing Microsoft'sVisualStudioproducts. Pythoncanalsobe usedinareal- timeinte rpreterfortestingcodesnipp etsbef oreaddingthemintoa normal"executable" . Pythonisclassifiedas ascripting language.Generall yspeaking , thisjust meansthatit'snotcompile dtocreatethemach ine-readabl e codeandthatt hecode is"tied-i nto"another programasacon trol routine.Compiledlanguage s,suchasC++,requirethe programmer torun thesource codethrou ghacompilerbeforeth esoftwareiscanbe usedby acomputer.D ependi ngontheprogram' ssize,thecompilation processcantak eminutest ohours. UsingPythonasac ontrolroutinemeansP ythonc anac tasa "glue"between di erentprograms.Forex ample,Pythonisoften used asthe scriptinglanguage forvideogames;whileth eheavy-dutyw ork ispe rformedbypre-compiledmodules ,Pythonc anactinacall/re- sponsefashion,suc hastaking controller inputand passingittothe appropriatemodule. Pythonisalsoconsi deredahigh-l evellanguage,mea ningittakes careofalot ofthe grunt workinv olved inprogrammi ng.Forexample, Pythonhasabuilt-in garbage col lectorsoyou,asapro grammer,don't reallyneed toworryaboutmemorym anagem entand memoryleaks, aco mmonoccurrencewhen usingolderlanguagessuchasC.

1.2.WHYANOTHE RTUTORIAL?5

Themain emphasisofP ythonisreadablecodeande nhanci ngpro- grammerproductivity. Thisisaccomplishedbyenforcingastrictway ofstructu ringthecodetoensureth ereadercanf ollowthelogicflow andbyha vingan"everyth ing'sincluded"mentality;th eprogrammer doesn'thavetow orryabouti ncludingal otofdi erentlibrari esor othersourcecod etomakehis programwork. Oneofthe mainar gumentsag ainstPython istheuseofwhitespace. Asshown inChapter3,ma nyoth erlanguagesrequire thepr ogrammer tous ebrackets,typ icallycurlybraces,i.e."{}", toidentifydi erent blocksofcode.WithPy thon,theseco deblocks areidentifiedbydi f- ferentamounts ofindentation. Peoplewhohavespenta lotof timewith"trad itional"langua ges feel thelackof bracketsisa badthi ng,whileotherspreferthewh itespa ce. Ultimately,itcomesdowntopersonalp refere nce.Ihappentol ike thelackofb racketsbe caus eit'sonelessthingIhav etotroubleshoot whentherei sacodingproble m.Imagi net hatonemissingbrac ketin severaldozentohundred sli nesofcodeis thereasonyourprogram won'twork.Nowim aginehavingt ogothr oughyourcodelinebyline tofin dthemissingbrac ket.(Yes ,programmingenvironmentsc anhelp butit 'sstilloneextr athingtoconsider).

1.2WhyAnot herTutorial?

Eventhough thereareseveralg reattutor ialsatthePy thonwebsite willbeonth epract icalfe aturesof thelanguage,i.e.Iwon'tgoin to thehistor yofthelanguageorthee soteri cwaysitca nbeused.Though itwillh elpifyou haveprogramm edbefo re,oratl eastcanunder stand programminglogicandprogramflow,Iwil ltrytomakesuret hat thingsstartouts lowsoyou don'tgetc onfused. Themain purposeofthi sbookistoteachpeople howtop rogram; Pythonjusthappenstobe thel anguageIhav echosento use.As mentionedabove,itisaveryfr iendlylanguagewhich letsy oulear n howtoprog ramwit houtgettinginyourway. Mostpeople,whenthe y decidetolearnprogr ammin g,wanttojumpint oC,C++,orJava. However,theselanguageshave little"gotchas"thatcanmak elearning di cultanddissu adepeopl efromcontinuingwithprogr amming.My

6CHAPTER1.INTRODUCTION

goalistopres entpro gramm inginafun,friendlyman nersoyouwill havethedesiret olearn more.

1.3GettingP ython

Asofth isrevis ion,Python 3.xhasbeenoutfors everalyears.M ost ofmyex perien ceiswithPython2.4and2.5,though mucho fmy knowledgewasgainedfromre adingboo kswrittenforversion 2.2.As youcansee ,itdoesn' tnecessaril ymeany ourknowledgeisobsolet e whenanewve rsi oncomeso ut.Usuallythenewerver sionssimplyadd newfeat ures,oftenfeaturestha tabeginnerwon' thaveaneedfor. Python3.xbreaksco mpatibili tywithprogramswritt enin2.xver- sions.However,muc hoftheknowledgeyougainfr omlearninga2 .x versionwillstillcarry over.Itju stmeansyouhavet obeawareofthe changestothelanguagewh enyou startusin gversion3.0.Plus,the installbaseof2.xi squitelargeandwon't begoin ga wayforqu itesome time.Dueto thefactth atmost Linuxdistrib utions(andMacOSX) stillhaveolderPython versionsinstal ledbydefault (someasoldas v2.4),manyofthecod eexamplesin thisbo okarewritt enforPython

2.x.Sp ecialnoteismadeofsign ificantchan gesbe tween2.xand 3.x

inthe chapter about19,butlearningeither versionwon'th army ou. Youcandown loadPytho nfromthePythonwebsit e(forWindows) oritma yalready beinstalledony oursystemify ou'reusinga Mac, Linux,or*BSD.Howe ver, theUnix-like operatingsystems,including OSX,ma ynotha vethelat estversio nsoyoumaywish toupgrad e, atleas ttoversion2.6.V ersio n2.6isamodificationof2 .5thatallows useof both2 .xcodeandcertain3 .0functions.Essent ially itletsy ou codein"lega cy"sty lewhilestillbeingabletou sethelatestfeat uresas desired,andtestingwhichl egacyfea tureswillbebrokenwhenmo ving to3.0. Forthos einterestedinus ingPythonviaaUSBthumbdrive,y ou maybeinte rested inPortablePython.Thisisaself-c ontai nedPython environmentthatyoucaneitherrunfr omthethum bdriveor inst all toyour computer.This isusefulforpeoplewhocan'tor don'twan t toins tallPythonbut wouldstillliketouseit. I'llassume youcanfigureouthow togetthe interacti veinterpreter running;ifyouneedhelp ,read thehelpp agesonthewebsite. Gener-

1.4.CONVENTIONS USEDINTHISBOOK7

allyspeakin gthough,youopen upacommandprompt(orterminal) andtype" python"atthe prompt.ThiswillopenaPytho nsessi on, allowingyoutoworkwitht hePythoni nterp reterinanint eractive manner.InWindows,typic all yyoujustgotothePytho nfileinAll

Programsandclickit.

1.4Convent ionsUsedinthisBook

Thelate stversionofPython is3.2whilethemostcurr ent"le gacy" versionis2.7.Iwilluse theter m3.xtosigni fya nythingin thePytho n stated. Theter m"*nix"isuse dtorefertoanyUnix -likel anguage,in- cludingLinuxandt hevariousflavorsofBSD (Fr eeBSD,OpenBSD,

NetBSD).ThoughMacOSXisbu iltuponFreeBSD, itisdi

erent enoughto notbel umpedinthe*nixl abel. Duetothew ord-wra pformatt ingforthisbook,someline sare automaticallyindentedwhentheyarereally onthesameline.Itmay makesomeoftheexamples confusing,especially becausePython uses "whitespace"like tabsandspacesassi gnificantarea s.Thus,aword - wrappedlinemayappea rtobeaninde ntedlinewh enitreallyisn't. Hopefullyyouwillbeabletofigu reoutifal ineisinte ntion allytabbed overorsimpl ywrappe d. Someofthewo rdsint hecodesec tionsarebolded .Thesea re keyword sinthePythonlan guage ;don'tuse thesewordsforvari able namesasitcancau seconf usion whenthepro gramtriestorun .Ifthe Pythoninterpreterfi ndsan"overwritten"keyword,itwillt hinkyou areusin gitintheexpected, defau ltmann erandcause anerror. Finally,ofthemaj orprogram sinthisbo okcanbefoundatth is book'swebsite:h ttp://python-ebook.blogspo t.com.

8CHAPTER1.INTRODUCTION

Chapter2

HowisPytho nDi

erent? Sowhati sPython?Ch ances youareaskingyourselft his.Youmay havefoundthisb ookbecause youwantto learntoprogra mbutdon't knowanythingabou tprogramminglanguages.Oryou mayhavehe ard ofprog ramminglanguageslikeC,C++,C#,orJav aandwantto knowwhatPyth onisandho witcomparesto"big name"l anguages.

HopefullyIcanexplainitfor you.

2.1PythonC oncepts

Ifyo urnotinteres tedinthe thehowsandwhysofPython,feelfree to skiptothenex tchapt er.Inthis chapterIwillt rytoexplaintothe readerwhyIthinkPyth oniso neo fthebestlanguag esavailableand whyit's agreatonetos ta rtprogrammingwit h.

2.1.1Dyn amicvs.StaticTypes

Pythonisadynamic-t ypedlang uage .Manyotherlanguagesarestati c typed,suchasC/C++an dJava.Astat ictype dlanguagere quires theprogra mmertoexplicitlytellthecomput erwhatt ypeof"thing" eachdataval ueis.Forex ample,inCify ouhadavar iablethatw asto containthepriceofsomet hing,youwoul dhavetodeclare thev ariable asa"flo at" type.Thistellsthec ompilerthattheo nlydatat hatcanbe 9

10CHAPTER2.HOWISPYTHO NDIFFER ENT?

usedfor thatv ariablemustbeaflo atingpointnumber,i.e.anum ber withadeci mal point.Ifanyotherdatav aluewasassignedtot ha t variable,thecompilerwouldg iveanerr orwhentryingtocompilethe program. Python,however,does n'trequirethis.Yousimpl ygiveyourvari - ablesnamesandas signvaluestoth em.Theinte rpretertakescareo f keepingtrackofwhatkin dsofobjectsyou rprogr amisusing .This alsome ansthatyoucanchange thesizeofthe valuesasyou dev elop theprogram.Sa yyouhav eanotherdecimal numbe r(a.k.a.afloating pointnumber) youneedinyourprogram. Withasta tictypedlan- guage,youhavetodec idetheme morysizethev ariabl ecantakewhen youfirst initializet hatvariable.Adoubleisafloating pointvalue thatcanhan dleamu chlargernumberthan anormal float(theactual memorysizesdependo ntheoperatinge nvironment).Ifyoud eclare it,yourpr ogramwillfail ;youwillhavetogobacka ndchanget hat variabletobeadouble. WithPython, itdoesn'tmatter.Yous implyg iveitwhatevernum- beryouwan tandPytho nwilltakecar eofmanipu latingitasneeded. Itev enworksforde rivedvalues.Fo rexample, sayyouaredividing twonu mbers.Oneisafloatingpo intnumber andon eis aninteger. Pythonrealizestha tit'smoreaccurateto keeptrackofdecima lssoit automaticallycalculatesthe resultasaflo atingpoint number.Here's whatitwou ldlook likeinthePytho ninterpreter . >>>6.0/2 3.0 >>>6/2.0 3.0 Asyouc ansee,itd oesn'tma tterwhichvalu eisont oporbottom; Python"sees"thatafloa tisbeing usedandgives theo utputasa decimalvalue.

2.1.2In terpretedvs.Compiled

Many"tradit ional"languagesarecompiled,meaningthesourcecode thedevelo perwritesisconvertedintomac hinelanguageby thecom - piler.Compiledlang uagesareusuallyusedf orlow-levelprogramming

2.1.PYTHONCONCE PTS11

(suchasdevicedrive rsand otherhardwareinteraction )andfasterpro- cessing,e.g.v ideogames. Becausethe languagei spre-converted tomachinecode, itcanbe processedbythecomput ermuchqui ckerbecause thecompilerhas alreadycheck edthecodeforerrorsandotherissu esthatcancau se theprogra mtofail.Thecompilerwo n'tcat challerrorsbut itdoes help.Thecaveatto using acompileristhatcom pilin gcanbeatime consumingtask;t heactualcompili ngtimecant akeseveral minutesto hourstocomplete dependingont heprogram.Ifer rorsarefound, the developerhastofindandfixt hemthenrerun thecompiler ;thi scycle continuesuntiltheprogramwork scorrectly. Pythonisconsidered anint erpretedlanguage.Itdoesn'thave a compiler;theinterpret erprocessesthe codelinebylineandcreatesa chinecodebuti tisn'tthesou rcecode. Becaus eofthisin-betwee n state,bytecode ismoretransferablebetweenoper atingsystems than machinecode;thishelps Pythonbecross-platform. Java isanother languagethatuses bytecode s. However,becausePythonus esaninterpreterratherthancomp iler, thecodepr ocessingcan beslower.Thebytecodestillhasto be"deci- phered"forusebythepr ocessor,wh ichtakes additi onaltime. Butthe benefittothisisth atthep rogrammerca nimmed iatelyseethe results ofhis code.Hed oesn'thavetow aitfor thecompilertodecideifthere isasyn tax errorsomewherethat causestheprogra mtocrash.

2.1.3Protot yping

Becauseofi nterpr etation,Pythonandsimilarlanguagesareusedfor rapidapplication developmentand programprototyping.Forexample, asi mpleprogramcanbecr eatedinjustafewhours andshownt oaquotesdbs_dbs14.pdfusesText_20