So i have a problem where i need to replace a character from a string in an array of strings by providing an x and a y coordinate. In this case, the output should be, that the second "0b000000" has a "1" instead of a "b". However, it either replaces all "b"s in that array, or doesn't replace anything. Here's my code, any help is appreciated:
def setpixel(x, y):
byte_array = [
"0b000000",
"0b000000",
"0b000000",
"0b000000",
"0b000000",
"0b000000",
"0b000000",
"0b000000"
]
line = byte_array[y - 1]
element = line[x - 1]
line.replace(element, "1")
print(byte_array)
setpixel(2, 2)
line.replaceto do?line.replacereturns a new string. It does not change a string in-place because string characters cannot be altered (strings are therefore immutable; they cannot be mutated)