Example: biology

An introduction to the Python programming language

IntroductionPython TutorialNumerics & PlottingStandard libraryAn introduction to the Python programminglanguagePrabhu RamachandranDepartment of Aerospace EngineeringIIT BombayJanuary 16, 2007 Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryOutline1 IntroductionIntroduction to Python2 Python TutorialPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneous3 Numerics & PlottingNumPy ArraysPlotting: MatplotlibSciPy4 Standard libraryQuick TourPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonOutline1 IntroductionIntroduction to Python2 Python TutorialPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneous3 Numerics & PlottingNumPy ArraysPlotting: MatplotlibSciPy4 Standard libraryQuick TourPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonIntroductionCreator and BDFL: Guido van RossumBDFL == B

Introduction Python Tutorial Numerics & Plotting Standard library An introduction to the Python programming ... High level, interpreted, modular, OO Easy to learn Easy to read code Much faster development cycle Powerful interactive interpreter ... >>> 2∗word + " world" # Arithmetic on strings

Tags:

  Introduction, Programming, Python, Language, Modular, Arithmetic, Introduction to the python programming language, Introduction to the python programming

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of An introduction to the Python programming language

1 IntroductionPython TutorialNumerics & PlottingStandard libraryAn introduction to the Python programminglanguagePrabhu RamachandranDepartment of Aerospace EngineeringIIT BombayJanuary 16, 2007 Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryOutline1 IntroductionIntroduction to Python2 Python TutorialPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneous3 Numerics & PlottingNumPy ArraysPlotting: MatplotlibSciPy4 Standard libraryQuick TourPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonOutline1 IntroductionIntroduction to Python2 Python TutorialPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneous3 Numerics & PlottingNumPy ArraysPlotting: MatplotlibSciPy4 Standard libraryQuick TourPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonIntroductionCreator and BDFL: Guido van RossumBDFL == Benevolent Dictator For LifeConceived in December 1989 The name Python .

2 Monty Python s Flying CircusCurrent stable version of Python is license (like BSD: no strings attached)Highly cross platformRuns on the Nokia series 60!Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonResourcesAvailable as part of anysaneGNU/Linux distributionWeb: : Tutorials:Official Python tutorial: of Python : into Python : RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonWhy Python ?High level, interpreted, modular , OOEasy to learnEasy to read codeMuch faster development cyclePowerful interactive interpreterRapid application developmentPowerful standard libraryInterfaces well to C++, C and FORTRAN librariesIn short:there is little you can t do with itPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonA quoteI came across Python and its Numerical extension in1998.

3 I quickly fell in love with Python programmingwhich is a remarkable statement to make about aprogramming language . If I had not seen others with thesame view, I might have seriously doubted my sanity. Travis Oliphant (creator of NumPy)Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonWhy not **lab?Open Source, FreePortablePython is a real programming language : large and smallprogramsCan do much more than just array and mathWrap large C++ codesBuild large code bases via SConsInteractive data analysis/plottingParallel applicationJob scheduling on a custom clusterMiscellaneous scriptsPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonWhy not Python ?

4 Can be slow for high-performance applicationsThis can be fairly easily overcome by using C/C++/FORTRAN extensionsPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonUse casesNASA: Python Streamlines Space Shuttle Mission DesignAstraZeneca Uses Python for Collaborative Drug Uses Python To Help MeteorologistsIndustrial Light & Magic Runs on PythonZope: Commercial grade CMSRedHat: install scripts, sys-admin toolsNumerous success stories: RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryIntroduction to PythonBefore we beginThis is only an introductionPython is a full-fledged programming languagePlease read the tutorialIt is very well written and can be read in one afternoonPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousOutline1 IntroductionIntroduction to Python2 Python TutorialPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneous3 Numerics & PlottingNumPy ArraysPlotting.

5 MatplotlibSciPy4 Standard libraryQuick TourPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousPreliminaries: The InterpreterPython is interpretedInterpreted vs. CompiledInterpreted languages allow for rapid testing/prototypingDynamically typedFull introspection of code at runtimeDid I say dynamic?Does not force OO or a particular programming paradigmdown your throat!Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousPreliminaries: IPythonRecommended interpreter, IPython: than the default Python shellSupports tab completion by defaultEasier object introspectionShell access!

6 Command system to allow extending its own behaviorSupports history (across sessions) and loggingCan be embedded in your own Python codeSupport for macrosA flexible framework for your own custom interpreterOther miscellaneous conveniencesWe ll get back to this laterPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousPreliminaries ..Will follow the Official Python tutorialNo lexical blockingIndentation specifies scopeLeads to easier to read code!Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousUsing the interpreterStarting up:pythonoripythonQuitting:Control-DorCo ntrol-Z(on Win32)Can use it like a calculatorCan execute one-liners via the-coption: Python -c"print hello world "Other options viapython -hPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousBasic conceptsDynamically typedAssignments need not specify a typea = 1a = ="foo"a = SomeClass ( )Comments.

7 A = 1#In l i n ecomments#Commentinal i n etoi t s e l ="#Thisisnotacomment!"Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousBasic conceptsNo lexical scopingScope determined by indentationf o rii nrange (10):p r i n t"insideloop:",# r i n ti , i ip r i n t"loopisdone!"#Thisisoutsidetheloop!Assi gnment to an object is by referenceEssentially,names are bound to objectsPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousOutline1 IntroductionIntroduction to Python2 Python TutorialPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneous3 Numerics & PlottingNumPy ArraysPlotting.

8 MatplotlibSciPy4 Standard libraryQuick TourPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousBasic typesBasic objects: numbers (float, int, long, complex), strings,tuples, lists, dictionaries, functions, classes, types are of two kinds:mutableandimmutableImmutable types: numbers, strings,Noneand tuplesImmutables cannot be changed in-place Mutable types: lists, dictionaries, instances, objects can be changed Prabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousWhat is an object?

9 A loose and informal but handy descriptionAnobjectis a particularinstanceof a generalclassof thingsReal world exampleConsider theclassof cars made by HondaA Honda Accord on the road, is a particularinstanceof thegeneralclassof carsIt is anobjectin the general sense of the termPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousObjects in a programming languageThe object in the computer follows a similar ideaAn object hasattributesandbehaviorObject contains or managesdata(attributes) and hasmethods(behavior)Together this lets one create representation of real things onthe computerProgrammers then create objects and manipulate themthrough their methods to get things doneIn Python everything is essentially an object you don t haveto worry about itPrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousNumbers>>> a = 1#I n t.

10 >>> l = 1000000L#Long>>> e = #f l o a t>>> f = #f l o a t>>> c = 1+1 j#Complex!>>>p r i n tf c / a( + j )>>>p r i n tc . real , c . >>> abs ( c ) RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousBoolean>>> t = True>>> f =nottFalse>>> fortTrue>>> fandtFalsePrabhu RamachandranIntroduction to PythonIntroductionPython TutorialNumerics & PlottingStandard libraryPreliminariesData typesControl flow, functionsModules, exceptions, classesMiscellaneousStringss = t h i sisastring s = Thisonehas"quotes"inside! s ="Thereversewith single quotes inside!"l ="Alongstringspanningseverallines\onemor el i n e\yetanother"t ="""At r i p l equotedstringdoesnotneedtobeescapedatthe endand"can have nested quotes"andwhatnot.


Related search queries