Teks sumber — English
Terjemahan — Bahasa Indonesia
Compile the *source* into a code or AST object. Code objects can be executed by :func:`exec` or :func:`eval`. *source* can either be a normal string, a byte string, or an AST object. Refer to the :mod:`ast` module documentation for information on how to work with AST objects.
Kompilasi *source* menjadi kode atau objek AST. Objek kode dapat dieksekusi oleh :func:`exec` atau :func:`eval`. *source* dapat berupa string normal, string byte, atau objek AST. Rujuk ke dokumentasi modul :mod:`ast` untuk informasi tentang cara bekerja dengan objek AST.
This function can also be used to execute arbitrary code objects (such as those created by :func:`compile`). In this case, pass a code object instead of a string. If the code object has been compiled with ``'exec'`` as the *mode* argument, :func:`eval`\'s return value will be ``None``.
Raises an :ref:`auditing event <auditing>` ``exec`` with the code object as the argument. Code compilation events may also be raised.
Memunculkan :ref:`auditing event <auditing>` ``exec`` dengan objek kode sebagai argumen. Kompilasi kode *events* juga dapat dimunculkan.
This function supports dynamic execution of Python code. *source* must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). If it is a code object, it is simply executed. In all cases, the code that's executed is expected to be valid as file input (see the section :ref:`file-input` in the Reference Manual). Be aware that the :keyword:`nonlocal`, :keyword:`yield`, and :keyword:`return` statements may not be used outside of function definitions even within the context of code passed to the :func:`exec` function. The return value is ``None``.
The *closure* argument specifies a closure--a tuple of cellvars. It's only valid when *source* is a code object containing :term:`free (closure) variables <closure variable>`. The length of the tuple must exactly match the length of the code object's :attr:`~codeobject.co_freevars` attribute.