0

What's the difference between a string and a byte string? When is it appropriate to use a byte string instead of a string?

More specifically, if I download an image or another binary file from the web, why do I need to convert it to a byte string before I can save it?

1
  • Are you referring to the difference between str and byte in Python3? Commented Mar 14, 2012 at 4:28

1 Answer 1

3

In 2.x, there is no difference; str is a sequence of bytes.

In 3.x, A byte string is identified by a byte literal, b'...'; it can be gotten from a string by encoding it to a specific charset, and it is the default type for most I/O operations.

Sign up to request clarification or add additional context in comments.

1 Comment

Why is it the default type for IO operations?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.