Explanation:
Creating a Memory View
x = memoryview(b"HELLO")
Explanation:
b"HELLO" creates a bytes object.
memoryview() creates a memory view of the bytes object.
The memory view is stored in the variable x.
Memory representation:
Index Character ASCII Value
0 H 72
1 E 69
2 L 76
3 L 76
4 O 79
Accessing the Last Element
x[-1]
Explanation:
-1 is a negative index.
It accesses the last element of the memoryview.
The last byte is 79 (ASCII value of 'O').
Printing the Value
print(x[-1])
Explanation:
x[-1] returns 79.
print() displays the returned value on the screen.
Output
79

0 Comments:
Post a Comment