Python code blocks do not display implied prints

The following Python code block does not display the value of x.

```{python}
x = 6
x
```

If print() is used, as below, the value of x is displayed.

```{python}
print(x)
```

Is there a chunk option or some other way to have Python code chunks display the results of an implied print?
Mark

The R Markdown python engine is not running code in interactive mode, but rather passing each chunk to the python interpreter as a small script (it's a bit more complicated than that, since all the python code chunks now execute in a single session by default thanks to reticulate, but that doesn't affect this issue).

Implicit printing in python only works when running the interpreter in interactive mode. See:

This video has a clear demonstration:

You can learn more about the R Markdown python language engine here:

and here:

2 Likes

Thank you. That was very helpful to me.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.