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

Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Edureka!
 
Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its Applications
Abhijeet Singh
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
Mohd Sajjad
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Agung Wahyudi
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
Nicholas I
 
Python ppt
Python pptPython ppt
Python ppt
Rohit Verma
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
St. Petersburg College
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
AnirudhaGaikwad4
 
How to download and install Python - lesson 2
How to download and install Python - lesson 2How to download and install Python - lesson 2
How to download and install Python - lesson 2
Shohel Rana
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
KrishnaMildain
 
Python
PythonPython
Python
GAnkitgupta
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
Aakashdata
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
ManishJha237
 
Python
PythonPython
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
Swarit Wadhe
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 

What's hot (20)

Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
 
Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its Applications
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
 
Python ppt
Python pptPython ppt
Python ppt
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
How to download and install Python - lesson 2
How to download and install Python - lesson 2How to download and install Python - lesson 2
How to download and install Python - lesson 2
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
python.ppt
python.pptpython.ppt
python.ppt
 
Python
PythonPython
Python
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python
PythonPython
Python
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python programming
Python  programmingPython  programming
Python programming
 

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
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in Python
Juan-Manuel Gimeno
 
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 (for beginners)
introduction to Python (for beginners)introduction to Python (for beginners)
introduction to Python (for beginners)
guobichrng
 
Introduction to Python.pptx
Introduction to Python.pptxIntroduction to Python.pptx
Introduction to Python.pptx
SamyakJain461
 

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 (for beginners)
introduction to Python (for beginners)introduction to Python (for beginners)
introduction to Python (for beginners)
 
Introduction to Python.pptx
Introduction to Python.pptxIntroduction to Python.pptx
Introduction to Python.pptx
 

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

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .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