What is a byte string (binary) in Python?—Differences from other data types

Asked 2 years ago, Updated 2 years ago, 110 views

This is a very basic question, but I'm sorry...

While reading the following pages, I am no longer sure what binary is (in Python).

7.1.structure—Interpret bytes as packed binary data

The basic questions are as follows:
The underlying question is, "All data should be binary, so why do you separate them from other data types and cut out only 'binary'?"

I understand that the following pages are different because they separate byte strings from other data types.

PyMOTW>structure – Handles binary data

The structure module provides a function that converts byte strings and native Python data types, such as numbers and strings.

Based on the following article, I suspect that binary and integer types have mechanisms specializing in handling integers, such as code information.

Handling binaries

Sometimes I want to read data from a file written in binary format.ascii can cause the data size to become too large.

The comments below are probably correct, but on the contrary, I don't know what other data types (such as int) are different from the binary and what additional information is added.

Differences between binary files and binary strings

In other words, even if the content is actually a letter, it explains that if you don't enter the data format and treat it as just a bit pattern, it's a binary column.

In addition, there is a contrast between binary data and text data, and the fact that there is one is understandable, and I am worried about whether it is the same as this context.

Binary and text data

Especially integer and string specifications and basic understanding of binary are fundamental to computer science, so I understand that listening itself is embarrassing, but I would appreciate it if someone could give me guidance...

I would be happy if there is a link that explains the specifications, but I would like to prioritize solving the questions at the beginning.

python binary

2022-09-30 21:29

2 Answers

I haven't checked the specifications yet, so I'm not sure about some of the information.

First, character data,
Previously (once upon a time...) character data was 8 bits of data (it seems that there were 7 bits, 6 bits, and so on) whereas Unicode is now the mainstream, so UTF-8 is an indefinite length of 8 bits.The UTF-16s vary in size, as you say in 16-bit increments (no fine indentations), and the inter-conversion is appropriate, so when you say it's just character data, you don't know what's inside.(Did you have any information about the character code?)

On the other hand, binary data means that they do not promise anything other than that the contents are binary.
I think it's from around here.


2022-09-30 21:29

I found a similar question (on another site).
First of all, I think I need to deepen my understanding of character code, binary, and data type.

What are the values of pack/unpack that handle binary data -teratail


2022-09-30 21:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.