Why Computers Think in Two States
Quick answer Boolean logic works with exactly two values because a wire can hold only two reliable voltage levels, and every comparison, condition and truth table you will write in Python rests on that single fact.
One honest note before we start. Boolean logic is listed in the CBSE Class 11 Computer Science (083) syllabus under Unit 1, Computer Systems and Organisation. It does not have a chapter of its own in the NCERT Class 11 Computer Science textbook. So do not waste time hunting for "the NCERT chapter on Boolean logic" — there isn't one. The topic is examined straight from the syllabus line, and reference books cover it on their own. That is also why the exercise questions later in this chapter are written in the style a CBSE reference book sets, and are not quoted from any numbered NCERT chapter.
Why two values and not ten? Inside a chip, a signal is just a voltage on a wire. Voltages drift — with heat, with the length of the wire, with electrical noise from the motor of a fan sitting next to the machine. If we tried to represent ten digits as ten different voltage levels, a small drift would turn a 6 into a 7 and the machine would be wrong. So hardware designers gave up on ten levels and kept only two, placed as far apart as possible: close to 0 volts and close to the supply voltage. Now a drift of a few tenths of a volt changes nothing, because the two levels are nowhere near each other. We call the low one 0 and the high one 1. Everything else — Aadhaar numbers, UPI transactions, a Reel you scroll past — is built on top of those two states.
Two states also gave us a piece of luck. Mathematics for exactly two values already existed. George Boole worked it out in his 1854 book An Investigation of the Laws of Thought, long before electronics. In 1937 Claude Shannon, in his master's thesis at MIT, showed that Boole's algebra describes switching circuits exactly. That is the link between a school algebra topic and the chip in your phone.
The vocabulary you must get right.
- A Boolean value (or truth value) is one of exactly two things: True or False.
- A Boolean constant is a fixed truth value written directly: True, False (or 1, 0).
- A Boolean variable is a name that holds one of those two values and nothing else. In circuit questions we call them A, B, C.
- A logical statement (proposition) is a sentence that is definitely true or definitely false — "Riya scored 78" is one; "Riya scored well" is not, because "well" has no fixed cut-off.
- A Boolean expression combines Boolean values using operators such as NOT, AND, OR.
Different books write the same two values in different clothes. All of these mean the same thing:
| Logic | Python | Hardware | Switch |
|---|---|---|---|
| 1 | True | HIGH | ON / closed |
| 0 | False | LOW | OFF / open |
Boolean values in Python. Python has a built-in type called bool with exactly two values, True and False. The capital letters matter — true is not defined and gives a NameError.
a = True
b = False
print(a, b)
print(type(a))
print(int(a), int(b))
print(True + True, True + False)
Real output:
True False
1 0
2 1
Look at the last line. True + True gave 2. That is not a bug. In Python bool is built on top of int, so True is 1 and False is 0 whenever arithmetic is involved. This is genuinely useful — it lets you count how many conditions are true just by adding them — but it also produces trick questions in exams, so remember it.
print(isinstance(True, int))
print(True == 1, False == 0)
True
True True
Truthiness: every value has a truth value. Python will happily treat non-Boolean values as True or False when a condition needs it. The rule is short: anything empty or zero counts as False, everything else counts as True.
print(bool(0), bool(1), bool(-7))
print(bool(0.0), bool(0.1))
print(bool(""), bool("0"), bool(" "))
print(bool([]), bool([0]))
False True True
False True
False True True
False True
Three of those catch students every year. bool(-7) is True — negative is not zero, so it is True. bool("0") is True — it is a string with one character in it, and a non-empty string is True regardless of what that character is. bool(" ") is True for the same reason: a space is a character. Only the truly empty string "" is False.
Worked example: turning a real rule into Boolean values. A school gives a merit certificate only if the student has passed and has at least 75% attendance. Take Riya: 78 marks, 68% attendance.
marks = 78
attendance = 68
P = marks >= 33
Q = attendance >= 75
print("P (passed) :", P)
print("Q (attendance) :", Q)
print("P and Q :", P and Q)
print("P or Q :", P or Q)
print("not P :", not P)
P (passed) : True
Q (attendance) : False
P and Q : False
P or Q : True
not P : False
Riya passed, so P is True. Her attendance is short, so Q is False. The certificate rule is P AND Q, which is False — no certificate. Notice what happened: a school rule written in English became two Boolean variables and one operator. That is the whole point of the subject.
The truth table. A Boolean expression has only finitely many possible inputs, so unlike ordinary algebra we can simply list every case and check. That list is a truth table. With n input variables there are 2n rows, because each variable independently takes 2 values.
n = 3
print("Variables:", n, "-> rows =", 2 ** n)
rows = 0
for A in [0, 1]:
for B in [0, 1]:
for C in [0, 1]:
rows = rows + 1
print(A, B, C)
print("Rows printed:", rows)
Variables: 3 -> rows = 8
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Rows printed: 8
Always write the rows in normal binary counting order — 00, 01, 10, 11 for two variables; 000, 001, 010, ... , 111 for three. Examiners expect that order, and it makes it obvious if you have skipped a row. Look at the eight lines the program printed: the nested for loops produced exactly that order for free, which is why we will use them for every table in this chapter.
- Hardware uses two states because two widely separated voltage levels survive noise and drift; ten levels would not.
- Python's bool has exactly two values, True and False, and bool is built on int — so True + True gives 2.
- Anything empty or zero is False; everything else is True, including -7, "0" and a single space " ".
- A truth table lists every possible input combination; n variables give 2**n rows, written in binary counting order.
- Boolean logic is a CBSE syllabus topic under Unit 1 with no NCERT Class 11 chapter of its own.
