SlideShare a Scribd company logo
Python: the Project, the Language and the Style

                                     Juan Manuel Gimeno Illa
                                       jmgimeno@diei.udl.cat

                                          October 2008




J.M.Gimeno (jmgimeno@diei.udl.cat)       Python: the Project, ...   October 2008   1 / 28
Outline

 1   Introduction

 2   Python, the project

 3   Python, the language
       References
       Functions
       Modules and Packages
       Namespaces and Scopes

 4   Python, the style

 5   Hands on Work


J.M.Gimeno (jmgimeno@diei.udl.cat)   Python: the Project, ...   October 2008   2 / 28
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
        A presentation of some aspects of Python (the language)
               We will focus on those elements and concepts that are most shocking
               for people coming from C, C++, Java, . . .
               A basic knowledge of the language is assumed (a casual reading the
               Python Tutorial is enough)
        We will begin to get into what me might call the python style of
        doing things (the style)
        (In the live session we will also present the interpreter (python), an
        enhanced interpreter (ipython) and the default integrated
        development environment (idle) among other things)




J.M.Gimeno (jmgimeno@diei.udl.cat)     Python: the Project, ...     October 2008   3 / 28
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
        A presentation of some aspects of Python (the language)
               We will focus on those elements and concepts that are most shocking
               for people coming from C, C++, Java, . . .
               A basic knowledge of the language is assumed (a casual reading the
               Python Tutorial is enough)
        We will begin to get into what me might call the python style of
        doing things (the style)
        (In the live session we will also present the interpreter (python), an
        enhanced interpreter (ipython) and the default integrated
        development environment (idle) among other things)




J.M.Gimeno (jmgimeno@diei.udl.cat)     Python: the Project, ...     October 2008   3 / 28
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
        A presentation of some aspects of Python (the language)
               We will focus on those elements and concepts that are most shocking
               for people coming from C, C++, Java, . . .
               A basic knowledge of the language is assumed (a casual reading the
               Python Tutorial is enough)
        We will begin to get into what me might call the python style of
        doing things (the style)
        (In the live session we will also present the interpreter (python), an
        enhanced interpreter (ipython) and the default integrated
        development environment (idle) among other things)




J.M.Gimeno (jmgimeno@diei.udl.cat)     Python: the Project, ...     October 2008   3 / 28
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
        A presentation of some aspects of Python (the language)
               We will focus on those elements and concepts that are most shocking
               for people coming from C, C++, Java, . . .
               A basic knowledge of the language is assumed (a casual reading the
               Python Tutorial is enough)
        We will begin to get into what me might call the python style of
        doing things (the style)
        (In the live session we will also present the interpreter (python), an
        enhanced interpreter (ipython) and the default integrated
        development environment (idle) among other things)




J.M.Gimeno (jmgimeno@diei.udl.cat)     Python: the Project, ...     October 2008   3 / 28
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
        A presentation of some aspects of Python (the language)
               We will focus on those elements and concepts that are most shocking
               for people coming from C, C++, Java, . . .
               A basic knowledge of the language is assumed (a casual reading the
               Python Tutorial is enough)
        We will begin to get into what me might call the python style of
        doing things (the style)
        (In the live session we will also present the interpreter (python), an
        enhanced interpreter (ipython) and the default integrated
        development environment (idle) among other things)




J.M.Gimeno (jmgimeno@diei.udl.cat)     Python: the Project, ...     October 2008   3 / 28
Introduction


What this session pretends


        A very light introduction to the making of Python (the project)
        A presentation of some aspects of Python (the language)
               We will focus on those elements and concepts that are most shocking
               for people coming from C, C++, Java, . . .
               A basic knowledge of the language is assumed (a casual reading the
               Python Tutorial is enough)
        We will begin to get into what me might call the python style of
        doing things (the style)
        (In the live session we will also present the interpreter (python), an
        enhanced interpreter (ipython) and the default integrated
        development environment (idle) among other things)




J.M.Gimeno (jmgimeno@diei.udl.cat)     Python: the Project, ...     October 2008   3 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Organization

        Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life)
        in 1990 and made public in 1991
        By the years, a process and an infrastructure for the development of
        Python have emerged:
        SourceForge: patches, bugs, etc.
        Mailing lists: python-dev, python-list
         Newsgroup: comp.lang.python
              PEPs: Python Enhancement Proposals
               SIGs: Special Interest Groups
               PSF: Python Software Foundation holds the copyright of
                       Python since version 2.1
        All of this is accessible from http://python.org
        Its a very open project provided you follow some rules!!


J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   4 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the project


Implementations
 The language Python has different implementations
     CPython: Standard implementation of the python language in C.
              Currently at version 2.6 of the language
        Jython: Java implementation that compiles python code to JVM
                byte-code
                Currently at version 2.2.1 of the language (alpha version
                2.5a3)
  IronPython: .NET implementation that compiles python code to CLR
              Currently at version 2.4 of the language (with minor
              differences)
     Stackless: enhanced version using micro-threads, implemented in C
                Currently at version 2.6 of the language
          PyPy: Rather experimental version of python written in python
 Python 3000: (or py3k) non-backwards compatible evolution of CPython
 We will use CPython versions 2.4 (very little differences)
J.M.Gimeno (jmgimeno@diei.udl.cat)            Python: the Project, ...   October 2008   5 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Variables and References
        A Python program access data values through references
        A reference is a name that refers to the location in memory of a value
        (object)
        (Python classes, functions and methods are also objects)
        References takes the form of variables (x), attributes (x.y) and items
        (x[y])
        A reference has no intrinsic type but gets the type of the referenced
        object (duck typing)
        The process of linking a reference to a value is called binding
        References can be rebound to another object
        Statements that create/modify bindings are assignment, def, class
        and import
        The del statement unbinds the reference (does not deletes the
        object)
        Bindings live in name-spaces (more on this later)
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   6 / 28
Python, the language    References


Binding, Rebinding and Unbinding
                                                            >>> l = []
                                                            >>> id(l)
                                                            -1210453844

      l gets bound though assignment to a list
      (id returns the identity of an object)
      l maintains its identity through method
      application
      But gets rebound with assignment
      In this case, augmented assignment does
      not rebind
      del statement unbinds the reference (it
      does not delete objects!!)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   7 / 28
Python, the language    References


Binding, Rebinding and Unbinding
                                                            >>> l = []
                                                            >>> id(l)
                                                            -1210453844
                                                            >>> l.append(1)
      l gets bound though assignment to a list              >>> id(l)
      (id returns the identity of an object)                -1210453844
      l maintains its identity through method
      application
      But gets rebound with assignment
      In this case, augmented assignment does
      not rebind
      del statement unbinds the reference (it
      does not delete objects!!)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   7 / 28
Python, the language    References


Binding, Rebinding and Unbinding
                                                            >>> l = []
                                                            >>> id(l)
                                                            -1210453844
                                                            >>> l.append(1)
      l gets bound though assignment to a list              >>> id(l)
      (id returns the identity of an object)                -1210453844
      l maintains its identity through method               >>> l = l + [2]
      application                                           >>> id(l)
      But gets rebound with assignment                      -1210467412
      In this case, augmented assignment does
      not rebind
      del statement unbinds the reference (it
      does not delete objects!!)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   7 / 28
Python, the language    References


Binding, Rebinding and Unbinding
                                                            >>> l = []
                                                            >>> id(l)
                                                            -1210453844
                                                            >>> l.append(1)
      l gets bound though assignment to a list              >>> id(l)
      (id returns the identity of an object)                -1210453844
      l maintains its identity through method               >>> l = l + [2]
      application                                           >>> id(l)
      But gets rebound with assignment                      -1210467412
      In this case, augmented assignment does               >>> l += [3]
      not rebind                                            >>> id(l)
      del statement unbinds the reference (it               -1210467412
      does not delete objects!!)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   7 / 28
Python, the language    References


Binding, Rebinding and Unbinding
                                                            >>> l = []
                                                            >>> id(l)
                                                            -1210453844
                                                            >>> l.append(1)
      l gets bound though assignment to a list              >>> id(l)
      (id returns the identity of an object)                -1210453844
      l maintains its identity through method               >>> l = l + [2]
      application                                           >>> id(l)
      But gets rebound with assignment                      -1210467412
      In this case, augmented assignment does               >>> l += [3]
      not rebind                                            >>> id(l)
      del statement unbinds the reference (it               -1210467412
      does not delete objects!!)                            >>> del l
                                                            >>> id(l)
                                                            Traceback (most recent call last):
                                                            File ’<stdin>’, line 1, in ?
                                                            NameError: name ’l’ is not defined



J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...           October 2008   7 / 28
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
             statement(s)



        Formal parameters can be
         Mandatory Each call must supply a value for the parameter
           Optional If the call does not supply a value, the default is used
        The def statement evaluates the expression and saves a reference to
        the expression value (the default value of the parameter) among the
        attributes of the function object



J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   8 / 28
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
             statement(s)



        Formal parameters can be
         Mandatory Each call must supply a value for the parameter
           Optional If the call does not supply a value, the default is used
        The def statement evaluates the expression and saves a reference to
        the expression value (the default value of the parameter) among the
        attributes of the function object



J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   8 / 28
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
             statement(s)



        Formal parameters can be
         Mandatory Each call must supply a value for the parameter
           Optional If the call does not supply a value, the default is used
        The def statement evaluates the expression and saves a reference to
        the expression value (the default value of the parameter) among the
        attributes of the function object



J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   8 / 28
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
             statement(s)



        Formal parameters can be
         Mandatory Each call must supply a value for the parameter
           Optional If the call does not supply a value, the default is used
        The def statement evaluates the expression and saves a reference to
        the expression value (the default value of the parameter) among the
        attributes of the function object



J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   8 / 28
Python, the language    Functions


The def statement


         def function-name(mandatory, optional=expression):
             statement(s)



        Formal parameters can be
         Mandatory Each call must supply a value for the parameter
           Optional If the call does not supply a value, the default is used
        The def statement evaluates the expression and saves a reference to
        the expression value (the default value of the parameter) among the
        attributes of the function object



J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   8 / 28
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function gets called.

                                                        >>> def f(x, y=None):
    >>> def f(x, y=[]):
                                                        ...     if y is None: y = []
    ...      y.append(x)
                                                        ...     y.append(x)
    ...      return y
                                                        ...     return y
    ...
                                                        ...
    >>> print f(23)
                                                        >>> print f(23)
    [23]
                                                        [23]
    >>> print f(42)
                                                        >>> print f(42)
    [23, 42]
                                                        [42]


 The y=None idiom is the standard way to deal with mutable defaults.
 Problem: Do you find another solution in this case?

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...    October 2008   9 / 28
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function gets called.

                                                        >>> def f(x, y=None):
    >>> def f(x, y=[]):
                                                        ...     if y is None: y = []
    ...      y.append(x)
                                                        ...     y.append(x)
    ...      return y
                                                        ...     return y
    ...
                                                        ...
    >>> print f(23)
                                                        >>> print f(23)
    [23]
                                                        [23]
    >>> print f(42)
                                                        >>> print f(42)
    [23, 42]
                                                        [42]


 The y=None idiom is the standard way to deal with mutable defaults.
 Problem: Do you find another solution in this case?

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...    October 2008   9 / 28
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function gets called.

                                                        >>> def f(x, y=None):
    >>> def f(x, y=[]):
                                                        ...     if y is None: y = []
    ...      y.append(x)
                                                        ...     y.append(x)
    ...      return y
                                                        ...     return y
    ...
                                                        ...
    >>> print f(23)
                                                        >>> print f(23)
    [23]
                                                        [23]
    >>> print f(42)
                                                        >>> print f(42)
    [23, 42]
                                                        [42]


 The y=None idiom is the standard way to deal with mutable defaults.
 Problem: Do you find another solution in this case?

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...    October 2008   9 / 28
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function gets called.

                                                        >>> def f(x, y=None):
    >>> def f(x, y=[]):
                                                        ...     if y is None: y = []
    ...      y.append(x)
                                                        ...     y.append(x)
    ...      return y
                                                        ...     return y
    ...
                                                        ...
    >>> print f(23)
                                                        >>> print f(23)
    [23]
                                                        [23]
    >>> print f(42)
                                                        >>> print f(42)
    [23, 42]
                                                        [42]


 The y=None idiom is the standard way to deal with mutable defaults.
 Problem: Do you find another solution in this case?

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...    October 2008   9 / 28
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function gets called.

                                                        >>> def f(x, y=None):
    >>> def f(x, y=[]):
                                                        ...     if y is None: y = []
    ...      y.append(x)
                                                        ...     y.append(x)
    ...      return y
                                                        ...     return y
    ...
                                                        ...
    >>> print f(23)
                                                        >>> print f(23)
    [23]
                                                        [23]
    >>> print f(42)
                                                        >>> print f(42)
    [23, 42]
                                                        [42]


 The y=None idiom is the standard way to deal with mutable defaults.
 Problem: Do you find another solution in this case?

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...    October 2008   9 / 28
Python, the language    Functions


Evaluation of the defaults
 The default expression is not evaluated when the function gets called.

                                                        >>> def f(x, y=None):
    >>> def f(x, y=[]):
                                                        ...     if y is None: y = []
    ...      y.append(x)
                                                        ...     y.append(x)
    ...      return y
                                                        ...     return y
    ...
                                                        ...
    >>> print f(23)
                                                        >>> print f(23)
    [23]
                                                        [23]
    >>> print f(42)
                                                        >>> print f(42)
    [23, 42]
                                                        [42]


 The y=None idiom is the standard way to deal with mutable defaults.
 Problem: Do you find another solution in this case?

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...    October 2008   9 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>> def spam(a, b, *args):
    ...     print a, b, args




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>> def spam(a, b, *args):
    ...     print a, b, args
    >>> spam(1, 2)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>> def spam(a, b, *args):
    ...     print a, b, args
    >>> spam(1, 2)
    1 2 ()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):
    ...        print a, b, args
    >>>    spam(1, 2)
    1 2    ()
    >>>    spam(b=1, a=2)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):
    ...        print a, b, args
    >>>    spam(1, 2)
    1 2    ()
    >>>    spam(b=1, a=2)
    2 1    ()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):
    ...        print a, b, args
    >>>    spam(1, 2)
    1 2    ()
    >>>    spam(b=1, a=2)
    2 1    ()
    >>>    spam(1, 2, 3, 4, 5)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):
    ...        print a, b, args
    >>>    spam(1, 2)
    1 2    ()
    >>>    spam(b=1, a=2)
    2 1    ()
    >>>    spam(1, 2, 3, 4, 5)
    1 2    (3, 4, 5)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):                             >>> def eggs(a, *args):
    ...        print a, b, args                               ...     spam(a, args)
    >>>    spam(1, 2)
    1 2    ()
    >>>    spam(b=1, a=2)
    2 1    ()
    >>>    spam(1, 2, 3, 4, 5)
    1 2    (3, 4, 5)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):                             >>> def eggs(a, *args):
    ...        print a, b, args                               ...     spam(a, args)
    >>>    spam(1, 2)                                         >>> eggs(1, 2, 3, 4, 5)
    1 2    ()
    >>>    spam(b=1, a=2)
    2 1    ()
    >>>    spam(1, 2, 3, 4, 5)
    1 2    (3, 4, 5)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):                             >>> def eggs(a, *args):
    ...        print a, b, args                               ...     spam(a, args)
    >>>    spam(1, 2)                                         >>> eggs(1, 2, 3, 4, 5)
    1 2    ()                                                 1 (2, 3, 4, 5) ()
    >>>    spam(b=1, a=2)
    2 1    ()
    >>>    spam(1, 2, 3, 4, 5)
    1 2    (3, 4, 5)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):                             >>> def eggs(a, *args):
    ...        print a, b, args                               ...     spam(a, args)
    >>>    spam(1, 2)                                         >>> eggs(1, 2, 3, 4, 5)
    1 2    ()                                                 1 (2, 3, 4, 5) ()
    >>>    spam(b=1, a=2)                                     >>> def ham(a, *args):
    2 1    ()                                                 ...     spam(a, *args)
    >>>    spam(1, 2, 3, 4, 5)
    1 2    (3, 4, 5)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):                             >>> def eggs(a, *args):
    ...        print a, b, args                               ...     spam(a, args)
    >>>    spam(1, 2)                                         >>> eggs(1, 2, 3, 4, 5)
    1 2    ()                                                 1 (2, 3, 4, 5) ()
    >>>    spam(b=1, a=2)                                     >>> def ham(a, *args):
    2 1    ()                                                 ...     spam(a, *args)
    >>>    spam(1, 2, 3, 4, 5)                                >>> ham(1, 2, 3, 4, 5)
    1 2    (3, 4, 5)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   10 / 28
Python, the language    Functions


Extra Positional Arguments

        At the end of the arguments list you may optionally add the special
        form *args
        This binds args to a tuple containing the extra values passed in the
        function call

    >>>    def spam(a, b, *args):                             >>> def eggs(a, *args):
    ...        print a, b, args                               ...     spam(a, args)
    >>>    spam(1, 2)                                         >>> eggs(1, 2, 3, 4, 5)
    1 2    ()                                                 1 (2, 3, 4, 5) ()
    >>>    spam(b=1, a=2)                                     >>> def ham(a, *args):
    2 1    ()                                                 ...     spam(a, *args)
    >>>    spam(1, 2, 3, 4, 5)                                >>> ham(1, 2, 3, 4, 5)
    1 2    (3, 4, 5)                                          1 2 (3, 4, 5)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...       October 2008   10 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):
  ...     print a, b, kw




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):
  ...     print a, b, kw
  >>> spam(1, 2)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):
  ...     print a, b, kw
  >>> spam(1, 2)
  1 2 {}




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>>    def spam(a, b, **kw):
  ...        print a, b, kw
  >>>    spam(1, 2)
  1 2    {}
  >>>    spam(b=1, a=2, c=3, d=4)




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>>    def spam(a, b, **kw):
  ...        print a, b, kw
  >>>    spam(1, 2)
  1 2    {}
  >>>    spam(b=1, a=2, c=3, d=4)
  2 1    {’c’: 3, ’d’: 4}




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>>    def spam(a, b, **kw):
  ...        print a, b, kw
  >>>    spam(1, 2)
  1 2    {}
  >>>    spam(b=1, a=2, c=3, d=4)
  2 1    {’c’: 3, ’d’: 4}
  >>>    def eggs(a, *args, **kw):
  ...        print a, args, kw




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>>    def spam(a, b, **kw):
  ...        print a, b, kw
  >>>    spam(1, 2)
  1 2    {}
  >>>    spam(b=1, a=2, c=3, d=4)
  2 1    {’c’: 3, ’d’: 4}
  >>>    def eggs(a, *args, **kw):
  ...        print a, args, kw
  >>>    eggs(1,2,3,4)


J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):
  ...     print a, b, kw
  >>> spam(1, 2)
  1 2 {}
  >>> spam(b=1, a=2, c=3, d=4)
  2 1 {’c’: 3, ’d’: 4}
  >>> def eggs(a, *args, **kw):
  ...     print a, args, kw
  >>> eggs(1,2,3,4)
  1 (2, 3, 4) {}

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...   October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):                                     >>> def ham(a,**kw):
  ...     print a, b, kw                                        ...     spam(a, kw)
  >>> spam(1, 2)
  1 2 {}
  >>> spam(b=1, a=2, c=3, d=4)
  2 1 {’c’: 3, ’d’: 4}
  >>> def eggs(a, *args, **kw):
  ...     print a, args, kw
  >>> eggs(1,2,3,4)
  1 (2, 3, 4) {}

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...        October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):                                     >>> def ham(a,**kw):
  ...     print a, b, kw                                        ...     spam(a, kw)
  >>> spam(1, 2)                                                >>> ham(1, b=2, c=3)
  1 2 {}
  >>> spam(b=1, a=2, c=3, d=4)
  2 1 {’c’: 3, ’d’: 4}
  >>> def eggs(a, *args, **kw):
  ...     print a, args, kw
  >>> eggs(1,2,3,4)
  1 (2, 3, 4) {}

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...        October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):                                     >>> def ham(a,**kw):
  ...     print a, b, kw                                        ...     spam(a, kw)
  >>> spam(1, 2)                                                >>> ham(1, b=2, c=3)
  1 2 {}                                                        1 {’c’: 3, ’b’: 2} {}
  >>> spam(b=1, a=2, c=3, d=4)
  2 1 {’c’: 3, ’d’: 4}
  >>> def eggs(a, *args, **kw):
  ...     print a, args, kw
  >>> eggs(1,2,3,4)
  1 (2, 3, 4) {}

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...        October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):                                     >>> def ham(a,**kw):
  ...     print a, b, kw                                        ...     spam(a, kw)
  >>> spam(1, 2)                                                >>> ham(1, b=2, c=3)
  1 2 {}                                                        1 {’c’: 3, ’b’: 2} {}
  >>> spam(b=1, a=2, c=3, d=4)                                  >>> def pram(a,**kw):
  2 1 {’c’: 3, ’d’: 4}                                          ...     spam(a, **kw)
  >>> def eggs(a, *args, **kw):
  ...     print a, args, kw
  >>> eggs(1,2,3,4)
  1 (2, 3, 4) {}

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...        October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):                                     >>> def ham(a,**kw):
  ...     print a, b, kw                                        ...     spam(a, kw)
  >>> spam(1, 2)                                                >>> ham(1, b=2, c=3)
  1 2 {}                                                        1 {’c’: 3, ’b’: 2} {}
  >>> spam(b=1, a=2, c=3, d=4)                                  >>> def pram(a,**kw):
  2 1 {’c’: 3, ’d’: 4}                                          ...     spam(a, **kw)
  >>> def eggs(a, *args, **kw):                                 >>> pram(1, b=2, c=3)
  ...     print a, args, kw
  >>> eggs(1,2,3,4)
  1 (2, 3, 4) {}

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...        October 2008   11 / 28
Python, the language    Functions


Extra Named Arguments
        At the end of the arguments list you may optionally add the special
        from **kwargs
        This binds kwargs to a dictionary containing the extra values passed
        in the function call and their names

  >>> def spam(a, b, **kw):                                     >>> def ham(a,**kw):
  ...     print a, b, kw                                        ...     spam(a, kw)
  >>> spam(1, 2)                                                >>> ham(1, b=2, c=3)
  1 2 {}                                                        1 {’c’: 3, ’b’: 2} {}
  >>> spam(b=1, a=2, c=3, d=4)                                  >>> def pram(a,**kw):
  2 1 {’c’: 3, ’d’: 4}                                          ...     spam(a, **kw)
  >>> def eggs(a, *args, **kw):                                 >>> pram(1, b=2, c=3)
  ...     print a, args, kw                                     1 2 {’c’: 3}
  >>> eggs(1,2,3,4)
  1 (2, 3, 4) {}

J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...        October 2008   11 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


Modules
        A typical Python program is made up of several source files
        Each source file corresponds to a module that groups variables,
        functions, classes, etc. for reuse
        A module explicitly establishes its dependencies using the import and
        from statements
               In some languages global variables provide a hidden mechanism for
               coupling between modules
               In Python global variables are not global to all modules: they are
               attributes of a module object (module.variable)
        Extensions, components coded in other languages such as C, C++,
        Java, C#, are treated as modules by the python code
        In Python everything is defined in a module:
               main program or interactive sessions in module main
               built-ins in preloaded module builtin accessible via import
                 builtin
               at loading, modules get an extra attribute named builtins which
               refers to either to module builtin or to its dictionary
J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   12 / 28
Python, the language    Modules and Packages


import modulename

  spam.py
  #!/usr/bin/env python
  # -*- coding: latin-1 -*-
  quot;quot;quot;Documentation of the
  spam module.quot;quot;quot;

  def eggs():
      quot;quot;quot;eggs documentationquot;quot;quot;
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py
  #!/usr/bin/env python
  # -*- coding: latin-1 -*-
  quot;quot;quot;Documentation of the
  spam module.quot;quot;quot;

  def eggs():
      quot;quot;quot;eggs documentationquot;quot;quot;
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python
  # -*- coding: latin-1 -*-
  quot;quot;quot;Documentation of the
  spam module.quot;quot;quot;

  def eggs():
      quot;quot;quot;eggs documentationquot;quot;quot;
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-
  quot;quot;quot;Documentation of the
  spam module.quot;quot;quot;

  def eggs():
      quot;quot;quot;eggs documentationquot;quot;quot;
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the
  spam module.quot;quot;quot;

  def eggs():
      quot;quot;quot;eggs documentationquot;quot;quot;
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the                           Traceback (most recent call last):
  spam module.quot;quot;quot;                                     File ’<stdin>’, line 1, in ?
                                                    NameError: name ’eggs’ is not defined
  def eggs():
      quot;quot;quot;eggs documentationquot;quot;quot;
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the                           Traceback (most recent call last):
  spam module.quot;quot;quot;                                     File ’<stdin>’, line 1, in ?
                                                    NameError: name ’eggs’ is not defined
  def eggs():                                       >>> spam.eggs()
      quot;quot;quot;eggs documentationquot;quot;quot;
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the                           Traceback (most recent call last):
  spam module.quot;quot;quot;                                     File ’<stdin>’, line 1, in ?
                                                    NameError: name ’eggs’ is not defined
  def eggs():                                       >>> spam.eggs()
      quot;quot;quot;eggs documentationquot;quot;quot;                      eggs !!!
      print quot;eggs !!!quot;

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the                           Traceback (most recent call last):
  spam module.quot;quot;quot;                                     File ’<stdin>’, line 1, in ?
                                                    NameError: name ’eggs’ is not defined
  def eggs():                                       >>> spam.eggs()
      quot;quot;quot;eggs documentationquot;quot;quot;                      eggs !!!
      print quot;eggs !!!quot;                              >>> ham=spam

  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the                           Traceback (most recent call last):
  spam module.quot;quot;quot;                                     File ’<stdin>’, line 1, in ?
                                                    NameError: name ’eggs’ is not defined
  def eggs():                                       >>> spam.eggs()
      quot;quot;quot;eggs documentationquot;quot;quot;                      eggs !!!
      print quot;eggs !!!quot;                              >>> ham=spam
                                                    >>> ham.spam()
  def spam(s):
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the                           Traceback (most recent call last):
  spam module.quot;quot;quot;                                     File ’<stdin>’, line 1, in ?
                                                    NameError: name ’eggs’ is not defined
  def eggs():                                       >>> spam.eggs()
      quot;quot;quot;eggs documentationquot;quot;quot;                      eggs !!!
      print quot;eggs !!!quot;                              >>> ham=spam
                                                    >>> ham.spam()
  def spam(s):                                      spam !!!
      quot;quot;quot;spam documentationquot;quot;quot;
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python, the language    Modules and Packages


import modulename
                                                    >>> import spam
  spam.py                                           >>> spam
  #!/usr/bin/env python                             <module ’spam’ from ’spam.pyc’>
  # -*- coding: latin-1 -*-                         >>> eggs()
  quot;quot;quot;Documentation of the                           Traceback (most recent call last):
  spam module.quot;quot;quot;                                     File ’<stdin>’, line 1, in ?
                                                    NameError: name ’eggs’ is not defined
  def eggs():                                       >>> spam.eggs()
      quot;quot;quot;eggs documentationquot;quot;quot;                      eggs !!!
      print quot;eggs !!!quot;                              >>> ham=spam
                                                    >>> ham.spam()
  def spam(s):                                      spam !!!
      quot;quot;quot;spam documentationquot;quot;quot;                      >>> dir()
      print quot;spam !!!quot;

  if __name__ == quot;__main__quot;:
      eggs()




J.M.Gimeno (jmgimeno@diei.udl.cat)             Python: the Project, ...             October 2008   13 / 28
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style
Python: the Project, the Language and the Style

More Related Content

What's hot

Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie
 
introduction to Python (for beginners)
introduction to Python (for beginners)introduction to Python (for beginners)
introduction to Python (for beginners)
guobichrng
 
Python ppt
Python pptPython ppt
Python ppt
Mohita Pandey
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
primeteacher32
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
Sumit Satam
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
Kanchilug
 
Python final ppt
Python final pptPython final ppt
Python final ppt
Ripal Ranpara
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
Vijay Chaitanya
 
File Handling in Python
File Handling in PythonFile Handling in Python
Basics of python
Basics of pythonBasics of python
Basics of python
SurjeetSinghSurjeetS
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
Aakashdata
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Yi-Fan Chu
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Python Summer Internship
Python Summer InternshipPython Summer Internship
Python Summer Internship
Atul Kumar
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
R.h. Himel
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
Mohammad Golyani
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
Haitham El-Ghareeb
 
Java loops
Java loopsJava loops
Java loops
ricardovigan
 

What's hot (20)

Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
introduction to Python (for beginners)
introduction to Python (for beginners)introduction to Python (for beginners)
introduction to Python (for beginners)
 
Python ppt
Python pptPython ppt
Python ppt
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
File Handling in Python
File Handling in PythonFile Handling in Python
File Handling in Python
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python Summer Internship
Python Summer InternshipPython Summer Internship
Python Summer Internship
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Java loops
Java loopsJava loops
Java loops
 

Viewers also liked

Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
Dr.YNM
 
Python, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersPython, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for Engineers
Boey Pak Cheong
 
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot EngibaryanCommon MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Ashot Engibaryan
 
Microsoft Excel Seminar
Microsoft Excel SeminarMicrosoft Excel Seminar
Microsoft Excel Seminar
Meridian Career Institute
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
Tomer Gabel
 
Excel for Marketers - Why do you hate Excel (#Measurefest 2013)
Excel for Marketers - Why do you hate Excel (#Measurefest 2013)Excel for Marketers - Why do you hate Excel (#Measurefest 2013)
Excel for Marketers - Why do you hate Excel (#Measurefest 2013)
Russell McAthy
 
Advanced excel 2010 & 2013 updated Terrabiz
Advanced excel 2010 & 2013 updated TerrabizAdvanced excel 2010 & 2013 updated Terrabiz
Advanced excel 2010 & 2013 updated Terrabiz
Ahmed Yasir Khan
 
Verilerimi düzenliyorum
Verilerimi düzenliyorumVerilerimi düzenliyorum
Verilerimi düzenliyorumİsmail Keskin
 
Dili kullanmak
Dili kullanmakDili kullanmak
Dili kullanmak
Aytekin Özel
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Excel Excellence (Microsoft Excel training that "sticks"): Formulas
Excel Excellence (Microsoft Excel training that "sticks"): FormulasExcel Excellence (Microsoft Excel training that "sticks"): Formulas
Excel Excellence (Microsoft Excel training that "sticks"): Formulas
Laura Winger
 
Python Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutPython Tricks That You Can't Live Without
Python Tricks That You Can't Live Without
Audrey Roy
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
Patrick Nicolas
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
Bozhidar Bozhanov
 
Python 101
Python 101Python 101
Python 101
Ahmet SEĞMEN
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
University of Technology
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in Python
Juan-Manuel Gimeno
 
Excel ppt
Excel pptExcel ppt
Worksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 TutorialWorksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 Tutorial
SpreadsheetTrainer
 

Viewers also liked (20)

Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Python, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for EngineersPython, the Language of Science and Engineering for Engineers
Python, the Language of Science and Engineering for Engineers
 
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot EngibaryanCommon MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
 
Microsoft Excel Seminar
Microsoft Excel SeminarMicrosoft Excel Seminar
Microsoft Excel Seminar
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Excel for Marketers - Why do you hate Excel (#Measurefest 2013)
Excel for Marketers - Why do you hate Excel (#Measurefest 2013)Excel for Marketers - Why do you hate Excel (#Measurefest 2013)
Excel for Marketers - Why do you hate Excel (#Measurefest 2013)
 
Advanced excel 2010 & 2013 updated Terrabiz
Advanced excel 2010 & 2013 updated TerrabizAdvanced excel 2010 & 2013 updated Terrabiz
Advanced excel 2010 & 2013 updated Terrabiz
 
Verilerimi düzenliyorum
Verilerimi düzenliyorumVerilerimi düzenliyorum
Verilerimi düzenliyorum
 
Dili kullanmak
Dili kullanmakDili kullanmak
Dili kullanmak
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Excel Excellence (Microsoft Excel training that "sticks"): Formulas
Excel Excellence (Microsoft Excel training that "sticks"): FormulasExcel Excellence (Microsoft Excel training that "sticks"): Formulas
Excel Excellence (Microsoft Excel training that "sticks"): Formulas
 
Python Tricks That You Can't Live Without
Python Tricks That You Can't Live WithoutPython Tricks That You Can't Live Without
Python Tricks That You Can't Live Without
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Python 101
Python 101Python 101
Python 101
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in Python
 
Excel ppt
Excel pptExcel ppt
Excel ppt
 
Worksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 TutorialWorksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 Tutorial
 

Similar to Python: the Project, the Language and the Style

Python for beginners
Python for beginnersPython for beginners
Python for beginners
Ananda Kumar HN
 
Learn Python Python Introduction for Beginners.pdf
Learn Python  Python Introduction for Beginners.pdfLearn Python  Python Introduction for Beginners.pdf
Learn Python Python Introduction for Beginners.pdf
SudhanshiBakre1
 
Introduction-to-Python.pptx
Introduction-to-Python.pptxIntroduction-to-Python.pptx
Introduction-to-Python.pptx
wildcat9335
 
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
kashifmajeedjanjua
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
ismailmrribi
 
Behold the Power of Python
Behold the Power of PythonBehold the Power of Python
Behold the Power of Python
Sarah Dutkiewicz
 
summer t.pdf
summer t.pdfsummer t.pdf
summer t.pdf
RITVIKKAPOOR10
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
SudhanshiBakre1
 
Python intro
Python introPython intro
Python intro
rik0
 
Python Programming Draft PPT.pptx
Python Programming Draft PPT.pptxPython Programming Draft PPT.pptx
Python Programming Draft PPT.pptx
LakshmiNarayanaReddy48
 
Python Class 1
Python Class 1Python Class 1
Python Class 1
arijit banerjee
 
Python 101 For The Net Developer
Python 101 For The Net DeveloperPython 101 For The Net Developer
Python 101 For The Net Developer
Sarah Dutkiewicz
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
MuhammadBakri13
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptx
Kaviya452563
 
Introduction to Python for uploadttttt.pptx
Introduction to Python for uploadttttt.pptxIntroduction to Python for uploadttttt.pptx
Introduction to Python for uploadttttt.pptx
ssuser20431d
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
DrMohammed Qassim
 
Hello, Python
Hello, PythonHello, Python
Hello, Python
hardwyrd
 
what is python ?
what is python ? what is python ?
what is python ?
NetmaxTechnologies1
 
Introduction to Python.pptx
Introduction to Python.pptxIntroduction to Python.pptx
Introduction to Python.pptx
SamyakJain461
 
Python basic
Python basicPython basic
Python basic
radhikaadroja
 

Similar to Python: the Project, the Language and the Style (20)

Python for beginners
Python for beginnersPython for beginners
Python for beginners
 
Learn Python Python Introduction for Beginners.pdf
Learn Python  Python Introduction for Beginners.pdfLearn Python  Python Introduction for Beginners.pdf
Learn Python Python Introduction for Beginners.pdf
 
Introduction-to-Python.pptx
Introduction-to-Python.pptxIntroduction-to-Python.pptx
Introduction-to-Python.pptx
 
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
Behold the Power of Python
Behold the Power of PythonBehold the Power of Python
Behold the Power of Python
 
summer t.pdf
summer t.pdfsummer t.pdf
summer t.pdf
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python intro
Python introPython intro
Python intro
 
Python Programming Draft PPT.pptx
Python Programming Draft PPT.pptxPython Programming Draft PPT.pptx
Python Programming Draft PPT.pptx
 
Python Class 1
Python Class 1Python Class 1
Python Class 1
 
Python 101 For The Net Developer
Python 101 For The Net DeveloperPython 101 For The Net Developer
Python 101 For The Net Developer
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptx
 
Introduction to Python for uploadttttt.pptx
Introduction to Python for uploadttttt.pptxIntroduction to Python for uploadttttt.pptx
Introduction to Python for uploadttttt.pptx
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Hello, Python
Hello, PythonHello, Python
Hello, Python
 
what is python ?
what is python ? what is python ?
what is python ?
 
Introduction to Python.pptx
Introduction to Python.pptxIntroduction to Python.pptx
Introduction to Python.pptx
 
Python basic
Python basicPython basic
Python basic
 

More from Juan-Manuel Gimeno

Visualización de datos enlazados
Visualización de datos enlazadosVisualización de datos enlazados
Visualización de datos enlazados
Juan-Manuel Gimeno
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
Juan-Manuel Gimeno
 
Sistemas de recomendación
Sistemas de recomendaciónSistemas de recomendación
Sistemas de recomendación
Juan-Manuel Gimeno
 
Proves de Software (en Java amb JUnit)
Proves de Software (en Java amb JUnit)Proves de Software (en Java amb JUnit)
Proves de Software (en Java amb JUnit)
Juan-Manuel Gimeno
 
Conceptes bàsics de la Web 2.0
Conceptes bàsics de la Web 2.0Conceptes bàsics de la Web 2.0
Conceptes bàsics de la Web 2.0
Juan-Manuel Gimeno
 
Unicode (and Python)
Unicode (and Python)Unicode (and Python)
Unicode (and Python)
Juan-Manuel Gimeno
 
Metaclass Programming in Python
Metaclass Programming in PythonMetaclass Programming in Python
Metaclass Programming in Python
Juan-Manuel Gimeno
 

More from Juan-Manuel Gimeno (7)

Visualización de datos enlazados
Visualización de datos enlazadosVisualización de datos enlazados
Visualización de datos enlazados
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojure
 
Sistemas de recomendación
Sistemas de recomendaciónSistemas de recomendación
Sistemas de recomendación
 
Proves de Software (en Java amb JUnit)
Proves de Software (en Java amb JUnit)Proves de Software (en Java amb JUnit)
Proves de Software (en Java amb JUnit)
 
Conceptes bàsics de la Web 2.0
Conceptes bàsics de la Web 2.0Conceptes bàsics de la Web 2.0
Conceptes bàsics de la Web 2.0
 
Unicode (and Python)
Unicode (and Python)Unicode (and Python)
Unicode (and Python)
 
Metaclass Programming in Python
Metaclass Programming in PythonMetaclass Programming in Python
Metaclass Programming in Python
 

Recently uploaded

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Vivekanand Anglo Vedic Academy
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 

Recently uploaded (20)

Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 

Python: the Project, the Language and the Style

  • 1. Python: the Project, the Language and the Style Juan Manuel Gimeno Illa jmgimeno@diei.udl.cat October 2008 J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 1 / 28
  • 2. Outline 1 Introduction 2 Python, the project 3 Python, the language References Functions Modules and Packages Namespaces and Scopes 4 Python, the style 5 Hands on Work J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 2 / 28
  • 3. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  • 4. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  • 5. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  • 6. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  • 7. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  • 8. Introduction What this session pretends A very light introduction to the making of Python (the project) A presentation of some aspects of Python (the language) We will focus on those elements and concepts that are most shocking for people coming from C, C++, Java, . . . A basic knowledge of the language is assumed (a casual reading the Python Tutorial is enough) We will begin to get into what me might call the python style of doing things (the style) (In the live session we will also present the interpreter (python), an enhanced interpreter (ipython) and the default integrated development environment (idle) among other things) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 3 / 28
  • 9. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 10. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 11. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 12. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 13. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 14. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 15. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 16. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 17. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 18. Python, the project Organization Initiated by Guido van Rossum (BDFL: Benevolent Dictator For Life) in 1990 and made public in 1991 By the years, a process and an infrastructure for the development of Python have emerged: SourceForge: patches, bugs, etc. Mailing lists: python-dev, python-list Newsgroup: comp.lang.python PEPs: Python Enhancement Proposals SIGs: Special Interest Groups PSF: Python Software Foundation holds the copyright of Python since version 2.1 All of this is accessible from http://python.org Its a very open project provided you follow some rules!! J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 4 / 28
  • 19. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 20. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 21. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 22. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 23. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 24. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 25. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 26. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 27. Python, the project Implementations The language Python has different implementations CPython: Standard implementation of the python language in C. Currently at version 2.6 of the language Jython: Java implementation that compiles python code to JVM byte-code Currently at version 2.2.1 of the language (alpha version 2.5a3) IronPython: .NET implementation that compiles python code to CLR Currently at version 2.4 of the language (with minor differences) Stackless: enhanced version using micro-threads, implemented in C Currently at version 2.6 of the language PyPy: Rather experimental version of python written in python Python 3000: (or py3k) non-backwards compatible evolution of CPython We will use CPython versions 2.4 (very little differences) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 5 / 28
  • 28. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 29. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 30. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 31. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 32. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 33. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 34. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 35. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 36. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 37. Python, the language References Variables and References A Python program access data values through references A reference is a name that refers to the location in memory of a value (object) (Python classes, functions and methods are also objects) References takes the form of variables (x), attributes (x.y) and items (x[y]) A reference has no intrinsic type but gets the type of the referenced object (duck typing) The process of linking a reference to a value is called binding References can be rebound to another object Statements that create/modify bindings are assignment, def, class and import The del statement unbinds the reference (does not deletes the object) Bindings live in name-spaces (more on this later) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 6 / 28
  • 38. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 l gets bound though assignment to a list (id returns the identity of an object) l maintains its identity through method application But gets rebound with assignment In this case, augmented assignment does not rebind del statement unbinds the reference (it does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  • 39. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method application But gets rebound with assignment In this case, augmented assignment does not rebind del statement unbinds the reference (it does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  • 40. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method >>> l = l + [2] application >>> id(l) But gets rebound with assignment -1210467412 In this case, augmented assignment does not rebind del statement unbinds the reference (it does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  • 41. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method >>> l = l + [2] application >>> id(l) But gets rebound with assignment -1210467412 In this case, augmented assignment does >>> l += [3] not rebind >>> id(l) del statement unbinds the reference (it -1210467412 does not delete objects!!) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  • 42. Python, the language References Binding, Rebinding and Unbinding >>> l = [] >>> id(l) -1210453844 >>> l.append(1) l gets bound though assignment to a list >>> id(l) (id returns the identity of an object) -1210453844 l maintains its identity through method >>> l = l + [2] application >>> id(l) But gets rebound with assignment -1210467412 In this case, augmented assignment does >>> l += [3] not rebind >>> id(l) del statement unbinds the reference (it -1210467412 does not delete objects!!) >>> del l >>> id(l) Traceback (most recent call last): File ’<stdin>’, line 1, in ? NameError: name ’l’ is not defined J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 7 / 28
  • 43. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  • 44. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  • 45. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  • 46. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  • 47. Python, the language Functions The def statement def function-name(mandatory, optional=expression): statement(s) Formal parameters can be Mandatory Each call must supply a value for the parameter Optional If the call does not supply a value, the default is used The def statement evaluates the expression and saves a reference to the expression value (the default value of the parameter) among the attributes of the function object J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 8 / 28
  • 48. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  • 49. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  • 50. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  • 51. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  • 52. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  • 53. Python, the language Functions Evaluation of the defaults The default expression is not evaluated when the function gets called. >>> def f(x, y=None): >>> def f(x, y=[]): ... if y is None: y = [] ... y.append(x) ... y.append(x) ... return y ... return y ... ... >>> print f(23) >>> print f(23) [23] [23] >>> print f(42) >>> print f(42) [23, 42] [42] The y=None idiom is the standard way to deal with mutable defaults. Problem: Do you find another solution in this case? J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 9 / 28
  • 54. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 55. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 56. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 57. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 58. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 59. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 60. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 61. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 62. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): ... print a, b, args >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 63. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 64. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 65. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) 2 1 () >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 66. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) >>> def ham(a, *args): 2 1 () ... spam(a, *args) >>> spam(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 67. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) >>> def ham(a, *args): 2 1 () ... spam(a, *args) >>> spam(1, 2, 3, 4, 5) >>> ham(1, 2, 3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 68. Python, the language Functions Extra Positional Arguments At the end of the arguments list you may optionally add the special form *args This binds args to a tuple containing the extra values passed in the function call >>> def spam(a, b, *args): >>> def eggs(a, *args): ... print a, b, args ... spam(a, args) >>> spam(1, 2) >>> eggs(1, 2, 3, 4, 5) 1 2 () 1 (2, 3, 4, 5) () >>> spam(b=1, a=2) >>> def ham(a, *args): 2 1 () ... spam(a, *args) >>> spam(1, 2, 3, 4, 5) >>> ham(1, 2, 3, 4, 5) 1 2 (3, 4, 5) 1 2 (3, 4, 5) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 10 / 28
  • 69. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 70. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 71. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 72. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 73. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 74. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 75. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 76. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 77. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 78. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): ... print a, b, kw >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 79. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 80. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 81. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) 2 1 {’c’: 3, ’d’: 4} >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 82. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) >>> def pram(a,**kw): 2 1 {’c’: 3, ’d’: 4} ... spam(a, **kw) >>> def eggs(a, *args, **kw): ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 83. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) >>> def pram(a,**kw): 2 1 {’c’: 3, ’d’: 4} ... spam(a, **kw) >>> def eggs(a, *args, **kw): >>> pram(1, b=2, c=3) ... print a, args, kw >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 84. Python, the language Functions Extra Named Arguments At the end of the arguments list you may optionally add the special from **kwargs This binds kwargs to a dictionary containing the extra values passed in the function call and their names >>> def spam(a, b, **kw): >>> def ham(a,**kw): ... print a, b, kw ... spam(a, kw) >>> spam(1, 2) >>> ham(1, b=2, c=3) 1 2 {} 1 {’c’: 3, ’b’: 2} {} >>> spam(b=1, a=2, c=3, d=4) >>> def pram(a,**kw): 2 1 {’c’: 3, ’d’: 4} ... spam(a, **kw) >>> def eggs(a, *args, **kw): >>> pram(1, b=2, c=3) ... print a, args, kw 1 2 {’c’: 3} >>> eggs(1,2,3,4) 1 (2, 3, 4) {} J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 11 / 28
  • 85. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 86. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 87. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 88. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 89. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 90. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 91. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 92. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 93. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 94. Python, the language Modules and Packages Modules A typical Python program is made up of several source files Each source file corresponds to a module that groups variables, functions, classes, etc. for reuse A module explicitly establishes its dependencies using the import and from statements In some languages global variables provide a hidden mechanism for coupling between modules In Python global variables are not global to all modules: they are attributes of a module object (module.variable) Extensions, components coded in other languages such as C, C++, Java, C#, are treated as modules by the python code In Python everything is defined in a module: main program or interactive sessions in module main built-ins in preloaded module builtin accessible via import builtin at loading, modules get an extra attribute named builtins which refers to either to module builtin or to its dictionary J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 12 / 28
  • 95. Python, the language Modules and Packages import modulename spam.py #!/usr/bin/env python # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 96. Python, the language Modules and Packages import modulename >>> import spam spam.py #!/usr/bin/env python # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 97. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 98. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 99. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the spam module.quot;quot;quot; def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 100. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 101. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 102. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 103. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 104. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam >>> ham.spam() def spam(s): quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 105. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam >>> ham.spam() def spam(s): spam !!! quot;quot;quot;spam documentationquot;quot;quot; print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28
  • 106. Python, the language Modules and Packages import modulename >>> import spam spam.py >>> spam #!/usr/bin/env python <module ’spam’ from ’spam.pyc’> # -*- coding: latin-1 -*- >>> eggs() quot;quot;quot;Documentation of the Traceback (most recent call last): spam module.quot;quot;quot; File ’<stdin>’, line 1, in ? NameError: name ’eggs’ is not defined def eggs(): >>> spam.eggs() quot;quot;quot;eggs documentationquot;quot;quot; eggs !!! print quot;eggs !!!quot; >>> ham=spam >>> ham.spam() def spam(s): spam !!! quot;quot;quot;spam documentationquot;quot;quot; >>> dir() print quot;spam !!!quot; if __name__ == quot;__main__quot;: eggs() J.M.Gimeno (jmgimeno@diei.udl.cat) Python: the Project, ... October 2008 13 / 28