Compare Python code online

A small script where a function and its variables were renamed. Swap in your own .py files to find what changed between two versions. Tips for Python

Original
0 lines
Drop to load into original
Changed
0 lines
Drop to load into changed
−0+0
Original
Changed

About this Python comparison

Python reads cleanly, which makes it easy to miss a renamed variable or a changed constant when two versions look almost the same. A side-by-side Python diff points at every edited line and marks the names that changed inside it.

Indentation matters in Python, so whitespace changes are shown by default. You can hide them when you know they are only cosmetic.

What changed in this sample

  • calculate_sum(numbers) was renamed to compute_total(values).
  • The loop variable changed from num to value.
  • The test list went from 10–50 to 15–55, and the printed label from “Sum of the numbers” to “Total of the values”.
  • main() became run().

Tips for comparing Python

Keep indentation visible
Leave Ignore whitespace off for Python: a changed indent can move a line into or out of a block, which is a real change.
Compare requirements files
For requirements.txt or a list of imports, turn on Sort lines before comparing (under More) so a reordered list does not show up as changes.
Notebook cells
Copy the code of two notebook cells into the panes to compare them, or export both notebooks as .py scripts first.
Jump between changes
Press Alt + ↓ and Alt + ↑ to move through long scripts one change at a time.

How to compare Python online

  1. Paste the older version into Original and the newer one into Changed, or open a file on each side.
  2. Check that the syntax menu says Python, then pick split or unified view.
  3. Step through the changes with the arrows or Alt ↓, and use Settings for options such as ignoring blank lines.
  4. Save the comparison in your browser, share a link, or download it as a .diff, HTML or PDF.

Python comparison: questions

Can I compare two .py files directly?

Yes. Use the file button on each pane, or drop both files onto the page at once. Python highlighting is selected from the .py extension.

Will mixed tabs and spaces show up?

Yes, lines that differ only in tabs versus spaces show as changed. Turn on Ignore whitespace to treat them as equal.

Can I compare Jupyter notebooks?

A .ipynb file is JSON, so you can compare it as JSON, but the result includes outputs and metadata. Exporting to .py first gives a cleaner code-only diff.