On Thu, Apr 25, 2013 at 9:45 AM, Marc Tompkins <marc.tompk...@gmail.com> wrote:
>
> If you put quotes around your input, Python recognizes it as a string
> literal.  Python "executes" string literals by simply printing them to
> standard output - try it at a Python prompt sometime - which is probably not
> the behavior you were expecting, but doesn't throw an error either.

It's only printed in Python's interactive REPL (read-eval-print loop).

http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop

String literals, like all literals, are handled by the compiler.  The
instantiated string gets stored somewhere such as a __doc__ attribute,
a code object's constants, a function's defaults, etc.

In 2.x, built-in input() compiles and evaluates a temporary code
object (in CPython it uses PyRun_StringFlags) in the current globals
and locals. If the source string is just the literal, the compiled
bytecode is a LOAD followed by a RETURN:

    >>> code = compile('"boB"', '', 'eval')
    >>> dis.dis(code)
      1           0 LOAD_CONST               0 ('boB')
                   3 RETURN_VALUE
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to