SlideShare a Scribd company logo
1 of 58
Download to read offline
Introduction
     to
   Python
Aim of this talk


        Show you that Python is not a noddy language
    




        Get you interested in learning Python
    




                                                       2
Before we start




        Who am I?




                      3
Tim Penhey

        Otago University Comp Sci 1991­1994
    



        Intermittent contractor for 12 years
    



        Started working for Canonical over 2 years ago
    



        First started with Python 8 years ago after 
    


        reading “The Cathedral & the Bazaar”
        Python has been my primary development 
    


        language for around three years now

                                                         4
        5
Quick Question

        What languages are you tought as an 
    


        undergraduate now?


        When I was here we did: Pascal; Modula­2; 
    


        LISP; Prolog; Assembly; C; Haskell; ML; Ada; 
        and Objective C (kinda)



                                                        6
Python




    Not named after this...




                              7
        8
Python




    ... but this ...




                       9
        10
Python




    ... by this man ...




                          11
        12
Guido van Rossum

        Python's BDFL
    



        http://www.python.org/~guido/
    



        Blog http://neopythonic.blogspot.com/
    



        Now works for Google
    




                                                13
Python History

        Implementation started Dec 1989
    



        Feb 1991 released to alt.sources
    



        Jan 1994 1.0.0 released
    



        Oct 2000 2.0 released
    



        Oct 2008 2.6 released
    



        Dec 2008 3.0 released
    




        2.7 and 3.1 in development
    
                                           14
Python has...

        very clear, readable syntax
    



        strong introspection capabilities
    



        intuitive object orientation
    



        natural expression of procedural code
    



        full modularity, supporting hierarchical 
    


        packages
        exception­based error handling
    




                                                    15
Python has...

        very high level dynamic data types
    



        an extensive standard libraries and third party 
    


        modules for virtually every task
        extensions and modules easily written in C,   
    


        C++ (or Java for Jython, or .NET languages for 
        IronPython)
        the ability to be embedded within applications 
    


        as a scripting interface

                                                           16
Python plays well with others

        Python can integrate with COM, .NET, and 
    


        CORBA objects
        Jython is Python for the JVM and can interact 
    


        fully with Java classes
        IronPython is Python for .NET
    



        Well supported in the Internet Communication 
    


        Engine (ICE ­ http://zeroc.com)


                                                         17
Python runs everywhere

        All major operating systems
    


            Windows
        



            Linux/Unix
        



            Mac
        



        And some lesser ones
    


            OS/2
        



            Amiga
        



            Nokia Series 60 cell phones
        



                                          18
Python is Open

        Implemented under an open source license
    


            Freely usable and distributable, even for 
        


            commercial use.


        Python Enhancement Proposals – PEP
    


            propose new features
        



            collecting community input
        



            documenting decisions
        



                                                         19
My Python Favourites #1

        The Zen of Python
    


            PEP 20
        



            Long time Pythoneer Tim Peters succinctly 
        


            channels the BDFL's guiding principles for Python's 
            design into 20 aphorisms, only 19 of which have 
            been written down.


        aphorism – A tersely phrased statement of a 
    


        truth or opinion 
                                                              20
The Zen of Python




    Beautiful is better than ugly.



                                     21
The Zen of Python




    Explicit is better than implicit.



                                        22
The Zen of Python




    Simple is better than complex.



                                     23
The Zen of Python




    Complex is better than 
       complicated.


                              24
The Zen of Python




    Flat is better than nested.



                                  25
The Zen of Python




    Sparse is better than dense.



                                   26
The Zen of Python




    Readability counts.



                          27
The Zen of Python




    Special cases aren't special 
     enough to break the rules.


                                    28
The Zen of Python




    Although practicality beats 
              purity.


                                   29
The Zen of Python




    Errors should never pass 
             silently.


                                30
The Zen of Python




    Unless explicitly silenced.



                                  31
The Zen of Python




    In the face of ambiguity, refuse 
         the temptation to guess.


                                    32
The Zen of Python




     There should be one — and 
    preferably only one — obvious 
             way to do it.


                                 33
The Zen of Python




    Although that way may not be 
     obvious at first unless you're 
                Dutch.


                                       34
The Zen of Python




    Now is better than never.



                                35
The Zen of Python




    Although never is often better 
           than right now.


                                      36
The Zen of Python




    If the implementation is hard to 
         explain, it's a bad idea.


                                    37
The Zen of Python




    If the implementation is easy to 
     explain, it may be a good idea.


                                    38
The Zen of Python




    Namespaces are one honking 
     great idea — let's do more of 
                those!


                                      39
Hello World

        Python 2.6
    



            print “Hello World”
        




        Pyton 3.0
    



            print(“Hello World”)
        




                                       40
My Python Favourites #2

        The interactive interpreter
    




                                      41
Datatypes

        All the usual suspects
    


            Strings (Unicode)
        



            int
        



            bool
        



            float (only one real type)
        



            complex
        



            files
        




                                         42
Unusual Suspects

        long — automatic promotion from int if needed
    



    >>> x = 1024
    >>> x ** 50
    327339060789614187001318969682759915221
    664204604306478948329136809613379640467
    455488327009232590415715088668412756007
    1009217256545885393053328527589376L


                                                        43
Built­in datastructures

        Tuples – Fixed Length
    



    (1, 2, 3, “Hello”, False)
        Lists
    



    [1, 2, 4, “Hello”, False]
        Dictionaries
    



    {42: “The answer”, “key”: “value”}
        Sets
    



    set([“list”, “of”, “values”])  
                                          44
Functions

        Python uses whitespace to determine blocks of 
    


        code (please don't use tabs)


    def greet(person):
        if person == “Tim”:
            print “Hello Master”
        else:
            print “Hello %s” % person
                                                     45
Parameter Passing

        Order is important unless using the name
    


            def foo(name, age, address)
        


            foo('Tim', address='Home', age=36)
        




        Default arguments are supported
    


            def greet(name='World')
        




        Variable length args acceptable as a list or dict
    


            def foo(*args, **kwargs)
        
                                                            46
Classes

class MyClass:
  quot;quot;quot;This is a docstring.quot;quot;quot;
  name = quot;Ericquot;
  def say(self):
    return quot;My name is %squot; % self.name


instance = MyClass()
print instance.say()
                                    47
Modules

        Any python file is considered a module
    



        Modules are loaded from the PYTHONPATH
    



        Nested modules are supported by using 
    


        directories.
            ~/src/lazr/enum/__init__.py
        



            If PYTHONPATH includes ~/src
        


            import lazr.enum
        




                                                 48
Exceptions

        Also used for flow control – StopIteration
    



        Exceptions are classes, and custom exceptions 
    


        are easy to write to store extra state information
        raise SomeException(params)
        try:
            # Do stuff
        except Exception, e:
            # Do something else
        finally:
                                                        49
            # Occurs after try and except block
Duck Typing

    If it walks like a duck and quacks like a duck, I 
       would call it a duck – James Whitcomb Riley


        There is no function or method overriding
    



        Methods can be checked using getattr
    



        Consider zope.interface
    




                                                         50
Batteries Included

        The Python standard library is very extensive
    


            regular expressions, codecs
        



            date and time, collections, theads and mutexs
        



            OS and shell level functions (mv, rm, ls)
        



            Support for SQLite and Berkley databases
        



            zlib, gzip, bz2, tarfile, csv, xml, md5, sha
        



            logging, subprocess, email, json
        



            httplib, imaplib, nntplib, smtplib
        



            and much, much more
        
                                                            51
Metaprogramming

        Descriptors
    




        Decorators
    




        Meta­classes
    




                                  52
My Python Favourites #3

        The Python debugger
    




    import pdb;
    pdb.set_trace()




                                     53
Other Domains

        Asynchronous Network Programming
    


            Twisted framework ­ http://twistedmatrix.com
        



        Scientific and Numeric
    


            Bioinformatics ­ biopython
        



            Linear algebra, signal processing – SciPy
        



            Fast compact multidimensional arrays – NumPy
        



        Desktop GUIs
    


            wxWidgets, GTK+, Qt
        


                                                           54
What is Python bad at?

        Anything that requires a lot of mathmatical 
    


        computations


        Anything that wants to use threads across 
    


        cores or CPUs


        Real­time systems
    




                                                       55
Work arounds

        Write extension libraries in C or C++
    




        Use multiple processes instead of multiple 
    


        threads


        Use a different language
    




                                                      56
NZ Python Users Group

        http://nzpug.org
    



        Regional meetings, DunPUG
    



        Mailing list using google groups
    



        Planning KiwiPyCon
    


            2 day event over a weekend in Christchurch
        



            7­8 November 2009 (that's this year!)
        




                                                         57
Questions?




                 58

More Related Content

What's hot

Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!Fariz Darari
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python pptPriyanka Pradhan
 
Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)IoT Code Lab
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptxAkshayAggarwal79
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Sergey Aganezov
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Pythonprimeteacher32
 

What's hot (20)

Python basic
Python basicPython basic
Python basic
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Python
PythonPython
Python
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Python basic
Python basicPython basic
Python basic
 
PyCharm demo
PyCharm demoPyCharm demo
PyCharm demo
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
 
Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)
 
Python ppt
Python pptPython ppt
Python ppt
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Python
 

Viewers also liked

Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101Tim Penhey
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageLaxman Puri
 
Python PPT
Python PPTPython PPT
Python PPTEdureka!
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3Youhei Sakurai
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewAn Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewBlue Elephant Consulting
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming LanguageTahani Al-Manie
 
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to PythonPython Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to PythonPython Ireland
 
Change document display
Change document displayChange document display
Change document displayRadosław Gref
 
Workshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensionesWorkshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensionesVisual Engineering
 
Unlock The Value Of Your Microsoft and SAP Investments
Unlock The Value Of Your Microsoft and SAP InvestmentsUnlock The Value Of Your Microsoft and SAP Investments
Unlock The Value Of Your Microsoft and SAP InvestmentsSAP Technology
 
Workshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operatorsWorkshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operatorsVisual Engineering
 
Workshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototypingWorkshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototypingVisual Engineering
 

Viewers also liked (20)

Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Python PPT
Python PPTPython PPT
Python PPT
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewAn Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm Review
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Python Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to PythonPython Ireland Feb '11 Talks: Introduction to Python
Python Ireland Feb '11 Talks: Introduction to Python
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Change document display
Change document displayChange document display
Change document display
 
Workshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensionesWorkshop iOS 3: Testing, protocolos y extensiones
Workshop iOS 3: Testing, protocolos y extensiones
 
Workshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte IWorkshop 16: EmberJS Parte I
Workshop 16: EmberJS Parte I
 
Unlock The Value Of Your Microsoft and SAP Investments
Unlock The Value Of Your Microsoft and SAP InvestmentsUnlock The Value Of Your Microsoft and SAP Investments
Unlock The Value Of Your Microsoft and SAP Investments
 
CDS Unit Testing
CDS Unit TestingCDS Unit Testing
CDS Unit Testing
 
Workshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operatorsWorkshop iOS 4: Closures, generics & operators
Workshop iOS 4: Closures, generics & operators
 
Workshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototypingWorkshop 11: Trendy web designs & prototyping
Workshop 11: Trendy web designs & prototyping
 

Similar to Introduction to Python

SoC Python Discussion Group
SoC Python Discussion GroupSoC Python Discussion Group
SoC Python Discussion Groupkrishna_dubba
 
Python 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUGPython 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUGNEWLUG
 
What's the Scoop with Python 3?
What's the Scoop with Python 3?What's the Scoop with Python 3?
What's the Scoop with Python 3?Python Ireland
 
Thinking Hybrid - Python/C++ Integration
Thinking Hybrid - Python/C++ IntegrationThinking Hybrid - Python/C++ Integration
Thinking Hybrid - Python/C++ IntegrationGuy K. Kloss
 
chapter-1-eng-getting-started-with-python.pptx
chapter-1-eng-getting-started-with-python.pptxchapter-1-eng-getting-started-with-python.pptx
chapter-1-eng-getting-started-with-python.pptxaniruddhmishra2007
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.pptRehnawilson1
 
Python @ PiTech - March 2009
Python @ PiTech - March 2009Python @ PiTech - March 2009
Python @ PiTech - March 2009tudorprodan
 
Practicing Python 3
Practicing Python 3Practicing Python 3
Practicing Python 3Mosky Liu
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd roundYouhei Sakurai
 
A Whirlwind Tour Of Python
A Whirlwind Tour Of PythonA Whirlwind Tour Of Python
A Whirlwind Tour Of PythonAsia Smith
 
Python Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-uPython Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-uNikola Plejic
 
What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)wesley chun
 
Python - The Good, The Bad and The ugly
Python - The Good, The Bad and The ugly Python - The Good, The Bad and The ugly
Python - The Good, The Bad and The ugly Eran Shlomo
 

Similar to Introduction to Python (20)

Os Goodger
Os GoodgerOs Goodger
Os Goodger
 
SoC Python Discussion Group
SoC Python Discussion GroupSoC Python Discussion Group
SoC Python Discussion Group
 
Python 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUGPython 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUG
 
What's the Scoop with Python 3?
What's the Scoop with Python 3?What's the Scoop with Python 3?
What's the Scoop with Python 3?
 
Thinking Hybrid - Python/C++ Integration
Thinking Hybrid - Python/C++ IntegrationThinking Hybrid - Python/C++ Integration
Thinking Hybrid - Python/C++ Integration
 
Violent python
Violent pythonViolent python
Violent python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
chapter-1-eng-getting-started-with-python.pptx
chapter-1-eng-getting-started-with-python.pptxchapter-1-eng-getting-started-with-python.pptx
chapter-1-eng-getting-started-with-python.pptx
 
Doing the Impossible
Doing the ImpossibleDoing the Impossible
Doing the Impossible
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Python in 15 minutes
Python in 15 minutesPython in 15 minutes
Python in 15 minutes
 
Python @ PiTech - March 2009
Python @ PiTech - March 2009Python @ PiTech - March 2009
Python @ PiTech - March 2009
 
Practicing Python 3
Practicing Python 3Practicing Python 3
Practicing Python 3
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd round
 
A Whirlwind Tour Of Python
A Whirlwind Tour Of PythonA Whirlwind Tour Of Python
A Whirlwind Tour Of Python
 
python into.pptx
python into.pptxpython into.pptx
python into.pptx
 
Python Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-uPython Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-u
 
What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)
 
Python - The Good, The Bad and The ugly
Python - The Good, The Bad and The ugly Python - The Good, The Bad and The ugly
Python - The Good, The Bad and The ugly
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Introduction to Python

  • 1. Introduction to Python
  • 2. Aim of this talk Show you that Python is not a noddy language  Get you interested in learning Python      2
  • 3. Before we start Who am I?     3
  • 4. Tim Penhey Otago University Comp Sci 1991­1994  Intermittent contractor for 12 years  Started working for Canonical over 2 years ago  First started with Python 8 years ago after   reading “The Cathedral & the Bazaar” Python has been my primary development   language for around three years now     4
  • 5.     5
  • 6. Quick Question What languages are you tought as an   undergraduate now? When I was here we did: Pascal; Modula­2;   LISP; Prolog; Assembly; C; Haskell; ML; Ada;  and Objective C (kinda)     6
  • 7. Python Not named after this...     7
  • 8.     8
  • 9. Python ... but this ...     9
  • 10.     10
  • 11. Python ... by this man ...     11
  • 12.     12
  • 13. Guido van Rossum Python's BDFL  http://www.python.org/~guido/  Blog http://neopythonic.blogspot.com/  Now works for Google      13
  • 14. Python History Implementation started Dec 1989  Feb 1991 released to alt.sources  Jan 1994 1.0.0 released  Oct 2000 2.0 released  Oct 2008 2.6 released  Dec 2008 3.0 released  2.7 and 3.1 in development      14
  • 15. Python has... very clear, readable syntax  strong introspection capabilities  intuitive object orientation  natural expression of procedural code  full modularity, supporting hierarchical   packages exception­based error handling      15
  • 16. Python has... very high level dynamic data types  an extensive standard libraries and third party   modules for virtually every task extensions and modules easily written in C,     C++ (or Java for Jython, or .NET languages for  IronPython) the ability to be embedded within applications   as a scripting interface     16
  • 17. Python plays well with others Python can integrate with COM, .NET, and   CORBA objects Jython is Python for the JVM and can interact   fully with Java classes IronPython is Python for .NET  Well supported in the Internet Communication   Engine (ICE ­ http://zeroc.com)     17
  • 18. Python runs everywhere All major operating systems  Windows  Linux/Unix  Mac  And some lesser ones  OS/2  Amiga  Nokia Series 60 cell phones      18
  • 19. Python is Open Implemented under an open source license  Freely usable and distributable, even for   commercial use. Python Enhancement Proposals – PEP  propose new features  collecting community input  documenting decisions      19
  • 20. My Python Favourites #1 The Zen of Python  PEP 20  Long time Pythoneer Tim Peters succinctly   channels the BDFL's guiding principles for Python's  design into 20 aphorisms, only 19 of which have  been written down. aphorism – A tersely phrased statement of a   truth or opinion      20
  • 21. The Zen of Python Beautiful is better than ugly.     21
  • 22. The Zen of Python Explicit is better than implicit.     22
  • 23. The Zen of Python Simple is better than complex.     23
  • 24. The Zen of Python Complex is better than  complicated.     24
  • 25. The Zen of Python Flat is better than nested.     25
  • 26. The Zen of Python Sparse is better than dense.     26
  • 27. The Zen of Python Readability counts.     27
  • 28. The Zen of Python Special cases aren't special  enough to break the rules.     28
  • 29. The Zen of Python Although practicality beats  purity.     29
  • 30. The Zen of Python Errors should never pass  silently.     30
  • 31. The Zen of Python Unless explicitly silenced.     31
  • 32. The Zen of Python In the face of ambiguity, refuse  the temptation to guess.     32
  • 33. The Zen of Python There should be one — and  preferably only one — obvious  way to do it.     33
  • 34. The Zen of Python Although that way may not be  obvious at first unless you're  Dutch.     34
  • 35. The Zen of Python Now is better than never.     35
  • 36. The Zen of Python Although never is often better  than right now.     36
  • 37. The Zen of Python If the implementation is hard to  explain, it's a bad idea.     37
  • 38. The Zen of Python If the implementation is easy to  explain, it may be a good idea.     38
  • 39. The Zen of Python Namespaces are one honking  great idea — let's do more of  those!     39
  • 40. Hello World Python 2.6  print “Hello World”  Pyton 3.0  print(“Hello World”)      40
  • 41. My Python Favourites #2 The interactive interpreter      41
  • 42. Datatypes All the usual suspects  Strings (Unicode)  int  bool  float (only one real type)  complex  files      42
  • 43. Unusual Suspects long — automatic promotion from int if needed  >>> x = 1024 >>> x ** 50 327339060789614187001318969682759915221 664204604306478948329136809613379640467 455488327009232590415715088668412756007 1009217256545885393053328527589376L     43
  • 44. Built­in datastructures Tuples – Fixed Length  (1, 2, 3, “Hello”, False) Lists  [1, 2, 4, “Hello”, False] Dictionaries  {42: “The answer”, “key”: “value”} Sets  set([“list”, “of”, “values”])     44
  • 45. Functions Python uses whitespace to determine blocks of   code (please don't use tabs) def greet(person):     if person == “Tim”:         print “Hello Master”     else:         print “Hello %s” % person     45
  • 46. Parameter Passing Order is important unless using the name  def foo(name, age, address)  foo('Tim', address='Home', age=36)  Default arguments are supported  def greet(name='World')  Variable length args acceptable as a list or dict  def foo(*args, **kwargs)      46
  • 48. Modules Any python file is considered a module  Modules are loaded from the PYTHONPATH  Nested modules are supported by using   directories. ~/src/lazr/enum/__init__.py  If PYTHONPATH includes ~/src  import lazr.enum      48
  • 49. Exceptions Also used for flow control – StopIteration  Exceptions are classes, and custom exceptions   are easy to write to store extra state information raise SomeException(params) try:     # Do stuff except Exception, e:     # Do something else finally:     49     # Occurs after try and except block
  • 50. Duck Typing If it walks like a duck and quacks like a duck, I  would call it a duck – James Whitcomb Riley There is no function or method overriding  Methods can be checked using getattr  Consider zope.interface      50
  • 51. Batteries Included The Python standard library is very extensive  regular expressions, codecs  date and time, collections, theads and mutexs  OS and shell level functions (mv, rm, ls)  Support for SQLite and Berkley databases  zlib, gzip, bz2, tarfile, csv, xml, md5, sha  logging, subprocess, email, json  httplib, imaplib, nntplib, smtplib  and much, much more      51
  • 52. Metaprogramming Descriptors  Decorators  Meta­classes      52
  • 53. My Python Favourites #3 The Python debugger  import pdb; pdb.set_trace()     53
  • 54. Other Domains Asynchronous Network Programming  Twisted framework ­ http://twistedmatrix.com  Scientific and Numeric  Bioinformatics ­ biopython  Linear algebra, signal processing – SciPy  Fast compact multidimensional arrays – NumPy  Desktop GUIs  wxWidgets, GTK+, Qt      54
  • 55. What is Python bad at? Anything that requires a lot of mathmatical   computations Anything that wants to use threads across   cores or CPUs Real­time systems      55
  • 56. Work arounds Write extension libraries in C or C++  Use multiple processes instead of multiple   threads Use a different language      56
  • 57. NZ Python Users Group http://nzpug.org  Regional meetings, DunPUG  Mailing list using google groups  Planning KiwiPyCon  2 day event over a weekend in Christchurch  7­8 November 2009 (that's this year!)      57
  • 58. Questions?     58