Member-only story

Python Tip #1- why add`>>>` in the Python example code?

Andrew Zhu
2 min readDec 2, 2024

--

In many Python example code, we see sample Python code started with >>> , like this:

Python code started with >>>

why do people do this?

The >>> symbols preceding the example code lines serve several purposes, largely rooted in conventions and readability enhancements:

Origins and Convention:

  1. Python Interpreter Prompt: In a Python interactive shell (e.g., IDLE, IPython, or simply running python in your terminal), the interpreter prompts the user with >>> to input commands. This symbol has become synonymous with "execute this line in Python."
  2. Documentation and Tutorial Conventions: Many Python documentation resources, tutorials, and books adopt this notation to indicate interactive shell examples. It visually distinguishes example code meant for execution from explanatory text.

Benefits in Example Code:

  • Immediate Clarity: At a glance, readers understand that these lines are executable code snippets, rather than just illustrative text.
  • Visual Separation: The >>> prefix provides a clear visual distinction between the example code and the surrounding explanatory text, enhancing overall readability.
  • Execution Hint: For newcomers to…

--

--

Andrew Zhu
Andrew Zhu

Written by Andrew Zhu

Working on AI stuffs | a HF Diffusers contributor | a ex-Data Scientist@MS | His LinkedIn is www.linkedin.com/in/andrew-zhu-23407223/

No responses yet