(bytes_or_str)
| 63 | |
| 64 | print("Example 3") |
| 65 | def to_str(bytes_or_str): |
| 66 | if isinstance(bytes_or_str, bytes): |
| 67 | value = bytes_or_str.decode("utf-8") |
| 68 | else: |
| 69 | value = bytes_or_str |
| 70 | return value # Instance of str |
| 71 | |
| 72 | print(repr(to_str(b"foo"))) |
| 73 | print(repr(to_str("bar"))) |