However, when you use the | operator on the next line, a 0 in the mask variable will not turn on the corresponding bit from a. A 1 is what will turn on a corresponding bit from a.

You need to turn on the third bit as you count from the right, and only that bit. Taking that into account, the value you are assigning to mask needs to be revised. After the 0b prefix, you currently have a 0 where you need to have 1 instead, and you have a 1 wherever you need to have 0 instead.

Thank you @appylpye but i am still a bit confused. Bear with me please. When it says the third bit from the right (does it mean --third bit only a = 0b10111(0)11 or all last three digits of a = 0b10111(011) ) and ALSO did you change 0s to 1s and vice verse in order to turn it on? English is my second language, sorry didn't understand the instruction well.

It means that you should turn on the “… third bit only a = 0b10111(0)11 …”, and leave all the other bits as they are given.

So you need to create a mask variable that turns that third bit on, but does not change any of the other bits. Consider the action of the | operator. Wherever there is a 0 in the mask variable, the action of a | mask will place whatever is in a into the result. Wherever there is a 1 in the mask variable, the action of a | mask will place a 1 into the result, that is, it will turn the corresponding bit on. So, there is only one place where you should have a 1 in the mask variable, and that is the third bit from the right.

After you have revised mask, you have this correct code …

a = 0b10111011
mask = 0b100
desired = a | mask
print bin(desired)

The output is …

0b10111111

The reason we place two 0s at the right end of mask is that the only bit we want to change in going from a to desired is the third bit from the right. Since we are using a | operation, any 0s in the mask will produce the same bit value in desired as occurs in the corresponding bit in a. Where there is a 1 in a, a 0 in mask will produce a 1 in the corresponding position in desired. Where there is a 0 in a, a 0 in mask will produce a 0 in the corresponding position in desired. However, the 1 in the third position from the right in mask will produce a 1 in the same position in desired, regardless of what bit value occurs in that position in a, and that is what we want - to turn on the third bit from the right, and leave everything else as is.