Byte of Python

download Byte of Python

of 157

  • date post

    12-Jul-2016
  • Category

    Documents

  • view

    23
  • download

    0

Embed Size (px)

description

Good starting resource to learn Python. Authored by Swaroop CH.

Transcript of Byte of Python

  • 01

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    TableofContentsIntroduction

    Dedication

    Preface

    AboutPython

    Installation

    FirstSteps

    Basics

    OperatorsandExpressions

    Controlflow

    Functions

    Modules

    DataStructures

    ProblemSolving

    ObjectOrientedProgramming

    InputandOutput

    Exceptions

    StandardLibrary

    More

    WhatNext

    Appendix:FLOSS

    Appendix:About

    Appendix:RevisionHistory

    Appendix:Translations

    Appendix:TranslationHow-to

    Feedback

    AByteofPython

    2

  • AByteofPython"AByteofPython"isafreebookonprogrammingusingthePythonlanguage.ItservesasatutorialorguidetothePythonlanguageforabeginneraudience.Ifallyouknowaboutcomputersishowtosavetextfiles,thenthisisthebookforyou.

    ForPythonversion3ThisbookwillteachyoutousePythonversion3.TherewillalsobeguidanceforyoutoadapttotheolderandmorecommonPythonversion2inthebook.

    WhoreadsAByteofPython?Herearewhatpeoplearesayingaboutthebook:

    Thisisthebestbeginner'stutorialI'veeverseen!Thankyouforyoureffort.--WaltMichalik

    Thebestthingifoundwas"AByteofPython",whichissimplyabrilliantbookforabeginner.It'swellwritten,theconceptsarewellexplainedwithselfevidentexamples.--JoshuaRobin

    Excellentgentleintroductiontoprogramming#Pythonforbeginners--ShanRajasekaran

    Bestnewbieguidetopython--NicksonKaigi

    starttolovepythonwitheverysinglepageread--HerbertFeutl

    perfectbeginnersguideforpython,willgiveukeytounlockmagicalworldofpython--Dilip

    Ishouldbedoingmyactual"work"butjustfound"AByteofPython".Agreatguidewithgreatexamples.--BiologistJohn

    RecentlystartedreadingaByteofpython.Awesomework.Andthattooforfree.Highlyrecommendedforaspiringpythonistas.--Mangesh

    AByteofPython,writtenbySwaroop.(thisisthebookI'mcurrentlyreading).Probablythebesttostartwith,andprobablythebestintheworldforeverynewbieorevenamoreexperienceduser.--Apostolos

    AByteofPython

    3Introduction

  • EnjoyingReading#ByteOfPythonby@swaroopchbestbookever--YuvrajSharma

    ThankyousomuchforwritingAByteOfPython.IjuststartedlearninghowtocodetwodaysagoandI'malreadybuildingsomesimplegames.YourguidehasbeenadreamandIjustwantedtoletyouknowhowvaluableithasbeen.--Franklin

    I'mfromDayanandasagarCollegeofEngineering(7thsem,CSE).Firstlyiwanttosaythatyourbook"Thebyteofpython"istoogoodabookforabeginnerinpythonlikeme.Theconceptsaresowellexplainedwithsimpleexamplesthathelpedmetoeasilylearnpython.Thankyousomuch.--Madhura

    Iama18yearoldITstudentstudyingatUniversityinIreland.Iwouldliketoexpressmygratitudetoyouforwritingyourbook"AByteofPython",Ialreadyhadknowledgeof3programminglangagues-C,JavaandJavascript,andPythonwasbyfartheeasiestlangagueIhaveeverlearned,andthatwasmainlybecauseyourbookwasfantasticandmadelearningpythonverysimpleandinteresting.ItisoneofthebestwrittenandeasytofollowprogrammingbooksIhaveeverread.Congratulationsandkeepupthegreatwork.--Matt

    Hi,I'mfromDominicanRepublic.MynameisPavel,recentlyIreadyourbookAByteofPythonandIconsideritexcellent!!:).Ilearntmuchfromalltheexamples.Yourbookisofgreathelpfornewbieslikeme...--PavelSimo

    IamastudentfromChina,Now,IhavereadyoubookAbyteofPython,Ohit'sbeautiful.Thebookisverysimplebutcanhelpallthefirstlearnners.YouknowIaminterestinginJavaandcloudcomputingmanytimes,ihavetocodingprogrammfortheserver,soithinkpythonisagoodchoice,finishyourbook,ithinkitsnotonlyagoodchoiceitsmustusethePython.MyEnglishisnotverywell,theemailtoyou,ijustwannathankyou!BestWishesforyouandyourfamily.--RoyLau

    IrecentlyfinishedreadingByteofPython,andIthoughtIreallyoughttothankyou.IwasverysadtoreachthefinalpagesasInowhavetogobacktodull,tediousoreillyoretc.manualsforlearningaboutpython.Anyway,Ireallyappreciateyourbook.SamuelYoung

    DearSwaroop,Iamtakingaclassfromaninstructorthathasnointerestinteaching.WeareusingLearningPython,secondedition,byO'Reilly.Itisnotatextforbeginnerwithoutanyprogrammingknowledge,andaninstructorthatshouldbeworkinginanotherfield.Thankyouverymuchforyourbook,withoutitIwouldbecluelessaboutPythonandprogramming.Thanksamillion,youareabletobreakthemessagedowntoalevelthatbeginnerscanunderstandandnoteveryonecan.--JosephDuarte

    Iloveyourbook!ItisthegreatestPythontutorialever,andaveryusefulreference.Brilliant,atruemasterpiece!Keepupthegoodwork!--Chris-AndrSommerseth

    AByteofPython

    4Introduction

  • Firstofall,Iwanttosaythankstoyouforthisgreatebook.Ithinkitisagoodbookforthosewhoarelookingforabeginner'stutorialforPython.Itisabouttwoorthereyearsago,Ithink,whenIfirstheardofthisbook.Atthattime,IamnotabletoreadsomebookinEnglishyet,soIgotachinesetranslation,whichtookmeintothegateofPythonprogramming.Recently,Irereadthisbook.Thistime,ofcourse,theenglishversion.Icouldn'tbelievethatIcanreadthewholebookwithoutmydictionaryathand.Ofcourse,itallduestoyourefforttomakethisbookaneasy-to-understandone.--myd7349

    I'mjuste-mailingyoutothankyouforwritingByteofPythononline.IhadbeenattemptingPythonforafewmonthspriortostumblingacrossyourbook,andalthoughImadelimitedsuccesswithpyGame,Inevercompletedaprogram.Thankstoyoursimplificationofthecategories,Pythonactuallyseemsareachablegoal.ItseemslikeIhavefinallylearnedthefoundationsandIcancontinueintomyrealgoal,gamedevelopment....Onceagain,thanksVERYmuchforplacingsuchastructuredandhelpfulguidetobasicprogrammingontheweb.ItshovedmeintoandoutofOOPwithanunderstandingwheretwotextbookshadfailed.--MattGallivan

    IwouldliketothankyouforyourbookAByteofPythonwhichimyselffindthebestwaytolearnpython.Iama15yearoldiliveinegyptmynameisAhmed.Pythonwasmysecondprogramminglanguageilearnvisualbasic6atschoolbutdidn'tenjoyit,howeverireallyenjoyedlearningpython.Imadetheaddressbookprogramandiwassucessful.iwilltrytostartmakemoreprogramsandreadpythonprograms(ifyoucouldtellmesourcethatwouldbehelpful).Iwillalsostartonlearningjavaandifyoucantellmewheretofindatutorialasgoodasyoursforjavathatwouldhelpmealot.Thanx.--AhmedMohammed

    AwonderfulresourceforbeginnerswantingtolearnmoreaboutPythonisthe110-pagePDFtutorialAByteofPythonbySwaroopCH.Itiswell-written,easytofollow,andmaybethebestintroductiontoPythonprogrammingavailable.--DrewAmes

    YesterdayIgotthroughmostofByteofPythononmyNokiaN800andit'stheeasiestandmostconciseintroductiontoPythonIhaveyetencountered.HighlyrecommendedasastartingpointforlearningPython.--JasonDelport

    ByteofVimandPythonby@swaroopchisbyfarthebestworksintechnicalwritingtome.Excellentreads#FeelGoodFactor--Surendran

    "Byteofpython"bestonebyfarman(inresponsetothequestion"Cananyonesuggestagood,inexpensiveresourceforlearningthebasicsofPython?")--JustinLoveTrue

    TheBookByteofpythonwasveryhelpful..Thanksbigtime:)Chinmay

    AByteofPython

    5Introduction

  • AlwaysbeenafanofAByteofPython-madeforbothnewandexperiencedprogrammers.--PatrickHarrington

    Istartedlearningpythonfewdaysagofromyourbook..thanksforsuchanicebook.itissowellwritten,youmademylifeeasy..soyoufoundanewfanofyours..thatsme:)tonsofthanks.--GadadhariBheem

    BeforeIstartedtolearnPython,I'veacquiredbasicprogrammingskillsinAssembly,C,C++,C#andJava.TheveryreasonIwantedtolearnPythonisit'spopular(peoplearetalkingaboutit)andpowerful(reality).ThisbookwrittenbyMr.Swaroopisaverygoodguideforbothbrand-newprogrammersandnewpythonprogrammers.Took10halfdaystogothroughit.GreatHelp!--FangBiyi(PhDCandidateECE,MichiganStateUniversity)

    Thankyoueversomuchforthisbook!!ThisbookclearedupmanyquestionsIhadaboutcertainaspectsofPythonsuchasobjectorientedprogramming.IdonotfeellikeanexpertatOObutIknowthisbookhelpedmeonafirststeportwo.Ihavenowwrittenseveralpythonprogramsthatactuallydorealthingsformeasasystemadministrator.Theyareallproceduralorientedbuttheyaresmallbymostpeoplesstandards.Again,thanksforthisbook.Thankyouforhavingitontheweb.--Bob

    IjustwanttothankyouforwritingthefirstbookonprogrammingI'veeverreallyread.Pythonisnowmyfirstlanguage,andIcanjustimagineallthepossibilities.SothankyouforgivingmethetoolstocreatethingsIneverwouldhaveimaginedIcoulddobefore.--"TheWalrus"

    IwantedtothankyouforwritingAByteOfPython(2&3Versions).IthasbeeninvaluabletomylearningexperienceinPython&Programmingingeneral.Needlesstosay,Iamabeginnerintheprogrammingworld,acoupleofmonthsofselfstudyuptothispoint.Ihadbeenusingyoutubetutorials&someotheronlinetutorialsincludingotherfreebooks.Idecidedtodigintoyourbookyesterday,&I'velearnedmoreonthefirstfewpagesthananyotherbookortutorial.AfewthingsIhadbeenconfusedabout,wereclearedrightupwithaGREATexample&explanation.Can'twaittoread(andlearn)more!!Thankyousomuchfornotonlywritingthebook,butforputtingitunderthecreativecommonslicense(free).Thankgoodnessthereareunselfishpeoplelikeyououttheretohelp&teachtherestofus.--Chris

    AByteofPython

    6Introduction

  • Iwroteyoubackin2011andIwasjustgettingintoPythonandwantedtothankyouforyourtutorial"AByteofPython".Withoutit,Iwouldhavefallenbythewayside.SincethenIhavegoneontoprogramanumberoffunctionsinmyorganizationwiththislanguagewithyetmoreonthehorizon.IwouldnotcallmyselfanadvancedprogrammerbyanystretchbutInoticetheoccasionalrequestforassistancenowfromotherssinceIstartedusingit.Idiscovered,whilereading"Byte"whyIhadceasedstudyingCandC++anditwasbecausethebookgiventomestartedoutwithanexamplecontaininganaugmentedassignment.Ofcourse,therewasnoexplanationforthisarrangementofoperatorsandIfellonmyheadtryingtomakesenseofwhatwasonthewrittenpage.AsIrecallitwasamostfrustratingexercisewhichIeventuallyabandoned.Doesn'tmeanCorC++isimpossibletolearn,oreventhatIamstupid,butitdoesmeanthatthedocumentationIworkedmywaythroughdidnotdefinethesymbolsandwordswhichisanessentialpartofanyinstruction.Justascomputerswillnotbeabletounderstandacomputerwordorcomputersymbolthatisoutsidethesyntaxforthelanguagebeingused,astudentnewtoanyfieldwilln