<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def escape(str):
 """Precede all special characters with a backslash."""

    out = ''
    for char in str:
        if char in '\\ ':
            out += '\\'
        out += char
    return out