In Qiskit, apply Pauli X or Z to a chosen qubit with qc.x(q) or qc.z(q). X flips computational-basis values; Z changes the phase of the |1⟩ component. Both are single-qubit instructions that can be added in sequence or alongside gates on other qubits.
Apply X or Z in Qiskit
Create a QuantumCircuit with enough qubits, then call the method for the qubit you want to affect:
As an Amazon Associate I earn from qualifying purchases.
from qiskit import QuantumCircuit
qc = QuantumCircuit(1)
qc.x(0) # apply Pauli X to qubit 0
qc.z(0) # then apply Pauli Z to qubit 0
print(qc.draw())
The official IBM Quantum lesson on bits, gates, and circuits demonstrates adding X to a single-qubit circuit; the XGate and ZGate API references document the corresponding gate methods. The call order is circuit order: in this example, X is applied first, followed by Z.
Use a specific qubit
For a two-qubit circuit, pass the index of the target qubit to each method:
#1 Best Overall
qc = QuantumCircuit(2)
qc.x(0) # X acts on qubit 0
qc.z(1) # Z acts on qubit 1
Each instruction acts on the selected qubit and leaves the other subsystem unchanged. When reading a drawn circuit or displayed bitstring, pay attention to the framework’s qubit-indexing and display conventions.
What X and Z do to a qubit
A qubit in a general pure state can be written as α|0⟩ + β|1⟩, where α and β are amplitudes. Applying a gate transforms those amplitudes as follows:
Rank #2
- Pauli X:
α|0⟩ + β|1⟩ → α|1⟩ + β|0⟩. - Pauli Z:
α|0⟩ + β|1⟩ → α|0⟩ − β|1⟩.
The matrix forms and computational-basis effects make the distinction clear:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute| Gate | Matrix | Effect on basis states | Common description | Qiskit method |
|---|---|---|---|---|
| Pauli X | [[0, 1], [1, 0]] |
|0⟩ → |1⟩; |1⟩ → |0⟩ |
Bit flip | qc.x(q) |
| Pauli Z | [[1, 0], [0, −1]] |
|0⟩ → |0⟩; |1⟩ → −|1⟩ |
Phase flip | qc.z(q) |
On the all-zero starting state, X on a single qubit produces |1⟩. Z leaves |0⟩ unchanged, so its effect is not visible on that state alone; its sign change matters when the |0⟩ and |1⟩ components are in superposition.
Check the circuit’s state
In the IBM Quantum learning workflow, the state can be inspected with Qiskit’s Statevector:
from qiskit.quantum_info import Statevector
state = Statevector(qc)
print(state)
This gives the state implied by the circuit instructions. To see measurement outcomes, a measurement operation and an execution or simulator workflow are needed; a statevector inspection by itself is not a measurement.
Rank #4
Does the order of X and Z matter?
Yes. On the same qubit, the operators anticommute: XZ = −ZX. Their resulting statevectors therefore differ by a minus sign if their order is reversed. For an isolated state, that overall sign is a global phase and does not change measurement probabilities. But operator order must not be treated as interchangeable in controlled operations or larger constructions, where phase relationships can affect the result.
Free tools Windows power users keep installed
One-click scans. No signup required.
Pauli gates versus rotation gates
Qiskit’s Pauli X and Z instructions are not exactly the same unitary matrices as π rotations around the corresponding axes: RX(π) = −iX and RZ(π) = −iZ. The difference is a global phase for an isolated state, so it does not change its measurement probabilities. Keep the factor when comparing exact unitary operators or composing gates in a larger construction.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

