Explanation:
๐น Line 1: Create a Bytes Object
x = b"ABC"
The prefix:
b
means this is a bytes object, not a normal string.
So:
b"ABC"
is stored as raw bytes.
Memory representation:
A → 65
B → 66
C → 67
Therefore:
b"ABC"
internally becomes:
[65, 66, 67]
๐น Line 2: Access First Element
x[0]
Current bytes object:
b"ABC"
Index:
0
points to:
A
Many people expect:
"A"
or
b"A"
But Python bytes work differently.
๐น Step 3: What Does Bytes Indexing Return?
For strings:
"ABC"[0]
Output:
"A"
But for bytes:
b"ABC"[0]
Output:
65
Because bytes indexing returns the integer value of the byte.
ASCII value of:
A
is:
65
๐น Step 4: Print Result
print(x[0])
becomes:
print(65)
Output:
65

0 Comments:
Post a Comment