Python code blocks do not display implied prints


#1

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


#2

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:
https://rstudio.github.io/reticulate/articles/r_markdown.html


#3

Thank you. That was very helpful to me.