SlideShare une entreprise Scribd logo
1  sur  206
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Edureka!
 
Introduction to Python IDLE | IDLE Tutorial | Edureka
Introduction to Python IDLE | IDLE Tutorial | EdurekaIntroduction to Python IDLE | IDLE Tutorial | Edureka
Introduction to Python IDLE | IDLE Tutorial | EdurekaEdureka!
 
Python Basics
Python BasicsPython Basics
Python BasicsPooja B S
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-pythonAakashdata
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | EdurekaEdureka!
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in PythonSumit Satam
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaEdureka!
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaEdureka!
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageDr.YNM
 

Tendances (20)

Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
 
Python programming
Python programmingPython programming
Python programming
 
Introduction to Python IDLE | IDLE Tutorial | Edureka
Introduction to Python IDLE | IDLE Tutorial | EdurekaIntroduction to Python IDLE | IDLE Tutorial | Edureka
Introduction to Python IDLE | IDLE Tutorial | Edureka
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python
PythonPython
Python
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 
Python basic
Python basicPython basic
Python basic
 
Introduction to the Python
Introduction to the PythonIntroduction to the Python
Introduction to the Python
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
 
Python
PythonPython
Python
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Python programming
Python  programmingPython  programming
Python programming
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 

En vedette

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 EngineersBoey 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 EngibaryanAshot Engibaryan
 
Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer 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 TerrabizAhmed Yasir Khan
 
Verilerimi düzenliyorum
Verilerimi düzenliyorumVerilerimi düzenliyorum
Verilerimi düzenliyorumİsmail Keskin
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin 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"): FormulasLaura 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 WithoutAudrey Roy
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in ScalaPatrick 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 uglyBozhidar Bozhanov
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in PythonJuan-Manuel Gimeno
 
Worksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 TutorialWorksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 TutorialSpreadsheetTrainer
 

En vedette (20)

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
 
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
 
Why Scala?
Why Scala?Why Scala?
Why Scala?
 
Mastering Python 3 I/O (Version 2)
Mastering Python 3 I/O (Version 2)Mastering Python 3 I/O (Version 2)
Mastering Python 3 I/O (Version 2)
 

Similaire à Python: the Project, the Language and the Style

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.pdfSudhanshiBakre1
 
Introduction-to-Python.pptx
Introduction-to-Python.pptxIntroduction-to-Python.pptx
Introduction-to-Python.pptxwildcat9335
 
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.ppt
452181636-Python-dsfdsfdsfdsfsdfdsfsdSeminar-1-ppt.pptkashifmajeedjanjua
 
Behold the Power of Python
Behold the Power of PythonBehold the Power of Python
Behold the Power of PythonSarah Dutkiewicz
 
Python intro
Python introPython intro
Python introrik0
 
Python 101 For The Net Developer
Python 101 For The Net DeveloperPython 101 For The Net Developer
Python 101 For The Net DeveloperSarah Dutkiewicz
 
python programming.pptx
python programming.pptxpython programming.pptx
python programming.pptxKaviya452563
 
Introduction to Python for uploadttttt.pptx
Introduction to Python for uploadttttt.pptxIntroduction to Python for uploadttttt.pptx
Introduction to Python for uploadttttt.pptxssuser20431d
 
Hello, Python
Hello, PythonHello, Python
Hello, Pythonhardwyrd
 
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.pptxSamyakJain461
 

Similaire à 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
 
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
 
Python basic
Python basicPython basic
Python basic
 

Plus de Juan-Manuel Gimeno

Visualización de datos enlazados
Visualización de datos enlazadosVisualización de datos enlazados
Visualización de datos enlazadosJuan-Manuel Gimeno
 
Functional programming in clojure
Functional programming in clojureFunctional programming in clojure
Functional programming in clojureJuan-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.0Juan-Manuel Gimeno
 
Metaclass Programming in Python
Metaclass Programming in PythonMetaclass Programming in Python
Metaclass Programming in PythonJuan-Manuel Gimeno
 

Plus de 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
 

Dernier

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 

Dernier (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.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