Qubits and Superposition
A qubit doesn't have to be definitely 0 or definitely 1, it can be in a superposition, a mix of both, described by two numbers (amplitudes) whose squared magnitudes give the probability of measuring each outcome.
The Hadamard gate
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(1)
qc.h(0) # put the qubit into an equal superposition of |0> and |1>
state = Statevector(qc)
print(state)
print(state.probabilities()) # [0.5, 0.5]
qc.h(0)applies the Hadamard gate, it takes a qubit starting at|0>and puts it into an equal superposition, neither definitely 0 nor definitely 1.Statevector(qc)computes the circuit's exact quantum state mathematically, without simulating any randomness, useful for inspecting what a circuit does before introducing measurement noise.state.probabilities()converts the state into the probability of measuring each outcome, here[0.5, 0.5]: a 50% chance of0, 50% chance of1.
Measurement collapses superposition
qc_measured = QuantumCircuit(1, 1)
qc_measured.h(0)
qc_measured.measure(0, 0)
# Once measured, the outcome is a single definite bit (0 or 1), chosen randomly
# according to the probabilities above, the superposition is gone.
print(qc_measured.draw())
Before measurement, a qubit in superposition genuinely holds both possibilities at once, that's not just "unknown to us", it's a real physical difference from a classical bit. The instant you measure it, that superposition collapses to one definite outcome, chosen randomly with the probabilities Statevector predicted. You cannot inspect a qubit's superposition without destroying it, this is the core reason quantum algorithms are designed so differently from classical ones.
TIP
Statevector is a teaching and debugging tool, it requires knowing the exact mathematical state, which is only possible on a simulator. Real quantum hardware can only ever give you measurement outcomes, never a peek at the superposition itself.