(bytes_or_str)
| 75 | |
| 76 | print("Example 4") |
| 77 | def to_bytes(bytes_or_str): |
| 78 | if isinstance(bytes_or_str, str): |
| 79 | value = bytes_or_str.encode("utf-8") |
| 80 | else: |
| 81 | value = bytes_or_str |
| 82 | return value # Instance of bytes |
| 83 | |
| 84 | print(repr(to_bytes(b"foo"))) |
| 85 | print(repr(to_bytes("bar"))) |