Feb-22-2017, 10:49 AM
I'm a beginner working on my first Python program. Using Python 3.6.
I don't understand what is actually stored in memory for the following two scenarios:
Scenario-1:
Scenario-2:
In trying to understand this, what is actually stored in memory for the two scenarios?
After line-1 is executed in both scenarios, aren't the bytes in memory identical?
For example:
In scenario-1, I assume blist[2] = hex 0B = decimal 11 is stored in memory.
In scenario-2, I assume blist[2] is also hex 0B = decimal 11 stored in memory.
Am I wrong? Please help me to understand this.
I don't understand what is actually stored in memory for the following two scenarios:
Scenario-1:
blist = b'\x76\x12\x0B\x08' blist[2] = 10 TypeError: 'bytes' object does not support item assignmentAfter a LOT of Googling, I saw a post that suggested using the list() method. So I tried scenario-2.
Scenario-2:
blist = list(b'\x76\x12\x0B\x08') blist[2] = 10 No errorAfter more Googling I learned that scenario-1 is a bytes type and that is immutable. Scenario-2 is a list type and lists are mutable which allows scenario-2 to work without errors.
In trying to understand this, what is actually stored in memory for the two scenarios?
After line-1 is executed in both scenarios, aren't the bytes in memory identical?
For example:
In scenario-1, I assume blist[2] = hex 0B = decimal 11 is stored in memory.
In scenario-2, I assume blist[2] is also hex 0B = decimal 11 stored in memory.
Am I wrong? Please help me to understand this.