154k views
0 votes
Write a docstring for this function

Write a docstring for this function-example-1

1 Answer

3 votes

Answer:

def word_wrap(message, length=79):

"""

Wrap a message to a specified line length.

Args:

message (str): The message to be wrapped.

length (int): The maximum line length. Default value is 79.

Returns:

str: The wrapped message.

"""

lines = message.split('\\')

output = []

for line in lines:

words = line.split(" ")

if len(words) > 0:

output_line = words[0]

for word in words[1:]:

if len(output_line + f' {word} ') > length:

output.append(output_line)

output_line = f"{word}"

else:

output_line = f"{output_line} {word}"

output.append(output_line)

return '\\'.join(output)

User Alii
by
5.5k points