Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 1 · Concurrency internals · RecapMemory views and buffer protocolpredict32 / 161
+100 XP
Task
📝 **Question:** Predict the exact output. \`mv = memoryview(data)\` is a zero-copy WINDOW into the bytearray. Then \`slice_view = mv[0:5]\` is a smaller window into the SAME buffer. The question: does writing through \`slice_view\` change \`data\`? 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Predict the output

Read the code carefully

data = bytearray(b"hello world")
mv = memoryview(data)
print(f"original:{data.decode()}")

mv[6:11] = b"PYTHN"
print(f"after_view_write:{data.decode()}")

slice_view = mv[0:5]
print(f"slice:{bytes(slice_view).decode()}")

slice_view[0] = ord("H")
print(f"data_now:{data.decode()}")
print(f"mv_view:{bytes(mv).decode()}")

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…