Skip to content

Commit 9b029f6

Browse files
Jarvis-J-JacobJarvis Jeason Jacobcclauss
authored
Add docstring to prompt() (#15092)
* Add docstring to prompt() * Enhance docstring for prompt function Updated prompt function docstring with examples. * Enhance prompt function with width parameter Updated prompt function to accept width parameter and modified example outputs accordingly. --------- Co-authored-by: Jarvis Jeason Jacob <jarvis@Jarviss-MacBook-Pro.local> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 636dd57 commit 9b029f6

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

searches/binary_tree_traversal.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ def post_order_iter(node: TreeNode) -> None:
259259

260260

261261
def prompt(s: str = "", width=50, char="*") -> str:
262+
"""Return a prompt string padded to the specified width.
263+
264+
>>> [prompt("Python", width=width) for width in range(8, 13)]
265+
[' Python ', ' Python *', '* Python *', '* Python **', '** Python **']
266+
267+
>>> prompt("Python", width=40, char=chr(0x1F40D))
268+
'🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍 Python 🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍'
269+
270+
>>> len(prompt("Python"))
271+
50
272+
273+
>>> prompt("Python", -200)
274+
' Python '
275+
"""
262276
if not s:
263277
return "\n" + width * char
264278
left, extra = divmod(width - len(s) - 2, 2)

0 commit comments

Comments
 (0)