# Details # ExternalEvaluate Usage • ExternalEvaluate["Python",code] executes a code string in a Python REPL and returns the results as a Wolfram Language expression.
• ExternalEvaluate["Python""String",code] executes the code string in a Python REPL and does not interpret the results.

# Data Types • Not all Python built-in types are supported. The supported Python types are:
•  bool True|False Boolean values array NumericArray arrays (from the NumPy library) bytearray ByteArray sequence of integers 0-255 bytes ByteArray immutable sequence of integers 0-255 complex Complex complex number date DateObject specific calendar date datetime DateObject specific date with time granularity Decimal Real arbitrary-precision real number dictionary Association association of keys and values float Real real-valued number Fraction Rational fraction object from the fractions module frozenset List unordered immutable set of unique values Image Image image (from Python PIL library) int Integer arbitrary-sized integer list List sequence of values long Integer arbitrary-sized integer None Null null value set List unordered set of unique values str String sequence of character values tuple List ordered sequence of values
• The precision of a Real returned from a Decimal object is maintained when returned from ExternalEvaluate.
• Python complex types are required to be real, and so any Complex expression returned from ExternalEvaluate will have real-valued components.

# Usage Notes • String templates (<**>) can be used to evaluate and insert Wolfram Language expressions into the Python code string.

# Examples

open allclose all

## Basic Examples(1)

Evaluate in Python and return the result:

Create a list in Python and return the result:

Type > to get a Python code cell that uses ExternalEvaluate to evaluate:

import math [math.sqrt(i) for i in range(10)]

Create a list with exponentials and logarithms:

[[i,math.exp(i),math.log(i)] for i in range(1,10)]

Create a list with the days of the week:

import calendar [calendar.day_name[i] for i in range(7)]

## Scope(2)

Start a session:

Evaluate a Boolean statement in Python and return the result:

Create a byte array in Python and return its equivalent in the Wolfram Language:

Another way to work with a byte array in Python:

Create a complex number in Python and return the result:

Create a date in Python and return it:

Close the session:

String templates can be used to insert Wolfram Language expressions into Python code

Set two variables:

The expression x^2+y^2 is evaluated in the Wolfram Language, and the result is converted and inserted into the Python code string:

The Python variable 'a' now holds the resulting list:

Close the session: