2.4 KiB
title, icon, createTime, permalink
| title | icon | createTime | permalink |
|---|---|---|---|
| Python | devicon-plain:python | 2025/10/08 21:53:58 | /en/guide/repl/python/ |
Overview
The theme provides Python code demonstration functionality, supporting online execution of Python code.
Installation
Online Python execution is powered by pyodide. Please ensure pyodide is available before use.
::: npm-to
npm install pyodide
:::
Configuration
This feature is disabled by default. You can enable it through configuration.
export default defineUserConfig({
theme: plumeTheme({
markdown: {
repl: {
python: true,
},
},
})
})
Usage
Use the ::: python-repl container syntax to wrap Python code blocks. The theme will detect the code blocks and add execution buttons.
::: warning The support for python-repl is limited and currently only supports:
- Execution of basic Python syntax (no backend dependencies)
- Import of basic Python libraries
- Standard output stream (stdout) capture
- If the last statement is an expression (and the code doesn't end with a semicolon), the expression value will be returned
- Exception message output
:::
Read-only Code Demo
Python code demos are read-only by default and cannot be edited.
::: python-repl title="Custom Title"
```python
# your python code
```
:::
Editable Code Demo
For online editing and execution, wrap the code block in the ::: python-repl editable container syntax.
::: python-repl editable title="Custom Title"
```python
# your python code
```
:::
Examples
Print Content
Input:
::: python-repl
```python
def hello_world():
return 'Hello World!'
hello_world()
```
:::
Output:
::: python-repl
def hello_world():
print('Hello World!')
hello_world()
:::
Arithmetic Operations
::: python-repl
def mul(a: int, b: int) -> int:
return a * b
print(mul(-2, 4))
:::
Editable Code Demo
Input:
::: python-repl editable
```python
class Contact:
def __init__(self, id: int, email: str):
self.id = id
self.email = email
contact = Contact(1, 'mary@gmail.com')
print(contact.id)
```
:::
Output:
::: python-repl editable
class Contact:
def __init__(self, id: int, email: str):
self.id = id
self.email = email
contact = Contact(1, 'mary@gmail.com')
print(contact.id)
:::