Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Qiskit, apply Pauli X or Z to a chosen qubit with qc.x(q) or qc.z(q). X swaps the computational-basis states |0⟩ and |1⟩; Z leaves |0⟩ unchanged and adds a minus sign to |1⟩. Here’s how to add either gate and understand its effect.

What the Pauli X and Z gates do

A one-qubit gate transforms the state of the selected qubit. The two Pauli gates have different effects on computational-basis states:

Gate Matrix Basis-state action Common description
Pauli X [[0, 1], [1, 0]] |0⟩ → |1⟩; |1⟩ → |0⟩ Bit flip
Pauli Z [[1, 0], [0, −1]] |0⟩ → |0⟩; |1⟩ → −|1⟩ Phase flip

For a general one-qubit state α|0⟩ + β|1⟩, X gives α|1⟩ + β|0⟩, while Z gives α|0⟩ − β|1⟩. Thus, Z changes the relative phase between the two components; it does not swap their basis labels. The gate definitions and circuit methods are documented in the Qiskit XGate reference and Qiskit ZGate reference.

Apply X or Z in a Qiskit circuit

Create a QuantumCircuit with enough qubits, then call the method for the gate you want on the selected qubit index. For the circuit-construction approach shown in IBM Quantum Learning’s bits, gates, and circuits lesson, the calls are:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • qc.x(q) applies Pauli X to qubit q.
  • qc.z(q) applies Pauli Z to qubit q.

Example: apply both gates

from qiskit import QuantumCircuit

qc = QuantumCircuit(1)
qc.x(0)  # apply X to qubit 0
qc.z(0)  # then apply Z to qubit 0

print(qc.draw())

Instructions are added in circuit order. Starting from the default all-zero state, the X first changes the qubit from |0⟩ to |1⟩; the following Z changes that component’s sign, giving −|1⟩. Drawing the circuit helps check which operation is applied to which wire.

Example: target different qubits

qc = QuantumCircuit(2)
qc.x(0)
qc.z(1)

Each instruction acts on the specified qubit and leaves the other subsystem untouched. When interpreting a displayed multi-qubit bitstring, follow Qiskit’s qubit and display-order conventions rather than assuming the leftmost displayed bit is qubit 0.

Check the result and interpret the gate order

In IBM Quantum Learning’s workflow, the circuit’s state can be inspected with Statevector(qc). For a circuit initialized in |0⟩, applying X produces |1⟩. Applying Z directly to |0⟩ leaves the state unchanged. To observe Z’s phase effect, the qubit must have a component in |1⟩, as in a superposition or after an X operation.

On the same qubit, the operators satisfy XZ = −ZX. The minus sign is a global phase when comparing the resulting isolated state, so it does not change that state’s measurement probabilities. But order and phase must not be discarded when building controlled operations or comparing exact unitaries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Pauli gates versus π rotations

In Qiskit’s gate conventions, an X rotation by π is RX(π) = −iX, and a Z rotation by π is RZ(π) = −iZ. These differ from the Pauli gates by a global phase. That phase does not affect measurement probabilities for an isolated state, but it matters if you are comparing exact unitary matrices or incorporating the operation into a larger controlled construction.

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.