# Guide to syntax changes by Python version?

**URL:** <https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715>\
**Category:** Python Help\
**Tags:** release\
**Created:** [November 3, 2022, 5:47pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715 "2022-11-03T17:47:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidMertz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidmertz/32/382_2.png) [@DavidMertz](https://discuss.python.org/u/DavidMertz)\
**Post date:** [November 3, 2022, 5:47pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/1 "2022-11-03T17:47:44Z")

</div>

Does anyone know of a quick guide to all the syntax changes by Python version?

I realize I could look through all the various “What’s New in Python 3.x” documents and eventually figure it out. Or at all the PEPs and which version they were accepted for.

But my hope is that someone wrote a blog post, or a page at [python.org](http://python.org) I’ve overlooked, that summarizes this in a single table, or with sections by version, or some other convenient form.

Note: For my current purpose, I’m interested in _syntax_ changes per se, not in semantic changes or stdlib additons, etc.

---

<div class="post-metadata">

**Author:** ![abdnafees](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abdnafees/32/9551_2.png) [@abdnafees](https://discuss.python.org/u/abdnafees)\
**Post date:** [November 3, 2022, 6:31pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/2 "2022-11-03T18:31:52Z")

</div>

Hey David,

This might be helpful.

> **[Python 3.11: Cool New Features for You to Try – Real Python](https://realpython.com/python311-new-features/)**
>
> In this tutorial, you'll explore what Python 3.11 brings to the table. You'll learn how Python 3.11 is the fastest and most user-friendly version of CPython yet, and learn about improvements to the typing system and to the asynchronous features of...

---

<div class="post-metadata">

**Author:** ![DavidMertz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidmertz/32/382_2.png) [@DavidMertz](https://discuss.python.org/u/DavidMertz)\
**Post date:** [November 3, 2022, 7:09pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/3 "2022-11-03T19:09:53Z")

</div>

That’s a nice document, but I’m more interested in e.g. a summary of which version added the walrus operator, which version added exception groups, which version added the switch statement

… or even like in a TV show I stopped watching a couple nights ago: “which version added context managers (with statement)?” I stopped watching when a character was portrayed as using `with` in 2003 :-). The lack of verisimilitude was painful to me.

---

<div class="post-metadata">

**Author:** ![abdnafees](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abdnafees/32/9551_2.png) [@abdnafees](https://discuss.python.org/u/abdnafees)\
**Post date:** [November 3, 2022, 7:19pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/4 "2022-11-03T19:19:29Z")

</div>

You are asking for a very specific use case but it makes sense. I wonder if there is such a document because I have never come across any in yet.

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [November 3, 2022, 7:52pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/5 "2022-11-03T19:52:34Z")

</div>

> [@DavidMertz](#):
>
> … or even like in a TV show I stopped watching a couple nights ago: “which version added context managers (with statement)?” I stopped watching when a character was portrayed as using `with` in 2003 :-). The lack of verisimilitude was painful to me.

I would LOVE to see a TV show in which this is the worst mistake made.

---

<div class="post-metadata">

**Author:** ![DavidMertz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidmertz/32/382_2.png) [@DavidMertz](https://discuss.python.org/u/DavidMertz)\
**Post date:** [November 3, 2022, 8:10pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/6 "2022-11-03T20:10:07Z")

</div>

Well, I only made it about 4 1/2 minutes into The Billion Dollar Code. I’m sure it gets worse later :-).

FWIW, my question isn’t because I want to rate TV shows as a Python old-timer.

I’ve started developing a FLOSS tool called Semantic Diff Tool (sdt) to hopefully aid development workflows (PR reviews, etc). One thing it will be able to do is utilize parse trees for different programming languages, but based on specific language versions.

It’s very, very early into development, but you are welcome to look at [GitHub - atlantistechnology/sdt: Semantic comparison of versioned files with git awareness](https://github.com/atlantistechnology/sdt). The tool itself is written in Golang, but it makes external calls to however many languages I manage to add. That said, it’s really not a _Python_ tool per se; it’s neither written in Python (other than one line calling `python -m ast -a`) nor restricted to analyzing Python. Still, that’s one of the first languages I added support for.

---

<div class="post-metadata">

**Author:** ![milliams](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/milliams/32/7063_2.png) [@milliams](https://discuss.python.org/u/milliams)\
**Post date:** [November 4, 2022, 12:11pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/7 "2022-11-04T12:11:52Z")

</div>

One approach would be to look at [cpython/Grammar at main · python/cpython · GitHub](https://github.com/python/cpython/tree/main/Grammar) by git tag and see what has changed.

---

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [November 4, 2022, 12:27pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/8 "2022-11-04T12:27:48Z")

</div>

> [@DavidMertz](#):
>
> For my current purpose, I’m interested in _syntax_ changes per se, not in semantic changes or stdlib additons, etc.

Syntax changes are always listed in the What’s New document.

> **[What’s New in Python](https://docs.python.org/3/whatsnew/)**
>
> The “What’s New in Python” series of essays takes tours through the most important changes between major Python versions. They are a “must read” for anyone wishing to stay up-to-date after a new re...

If stuff is missing from What’s New, it’s a documentation bug and should as such be fixed.

---

<div class="post-metadata">

**Author:** ![DavidMertz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidmertz/32/382_2.png) [@DavidMertz](https://discuss.python.org/u/DavidMertz)\
**Post date:** [November 4, 2022, 2:44pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/9 "2022-11-04T14:44:15Z")

</div>

I reckon I should probably write such a summary of the Whats New summaries myself. Addressing only _syntax_ shouldn’t require a long document (it’s not for the full BNF of each thing, just a one-sentence description of the overall change; not even the motivation for each).

So a question for folks here: how should I _publish_ such a document, assuming I get around to writing it. I reckon it should be permanently accessible; i.e. not a post on a transient discussion forum. All the URLs at my gnosis.cx domain have remained immutable for 20+ years at this point (except when my web host badly messed that up 2 years ago, but it’s generally fixed), so I suppose that’s an option. But that’s hardly a site anyone would look for.

@erlendaasland If I find anything actually missing in What’s New docs, I’ll definitely PR a change. But I very much doubt I will.

---

<div class="post-metadata">

**Author:** ![Stefan2](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/stefan2/32/18492_2.png) [@Stefan2](https://discuss.python.org/u/Stefan2)\
**Post date:** [November 4, 2022, 4:32pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/10 "2022-11-04T16:32:43Z")

</div>

> [@DavidMertz](#):
>
> about 4 1/2 minutes into The Billion Dollar Code

I watched the first 10 minutes, didn’t see any Python. Where is it?

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [November 4, 2022, 5:07pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/11 "2022-11-04T17:07:54Z")

</div>

> [@DavidMertz](#):
>
> So a question for folks here: how should I _publish_ such a document, assuming I get around to writing it. I reckon it should be permanently accessible; i.e. not a post on a transient discussion forum.

Hmm, sounds like a job for the Python wiki. [FrontPage - Python Wiki](https://wiki.python.org/moin/FrontPage) Make yourself an account there if you haven’t already, and hit us up on the pydotorg-www mailing list if you have any issues.

---

<div class="post-metadata">

**Author:** ![erlendaasland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/erlendaasland/32/4378_2.png) [@erlendaasland](https://discuss.python.org/u/erlendaasland)\
**Post date:** [November 5, 2022, 9:13am UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/12 "2022-11-05T09:13:02Z")

</div>

> [@DavidMertz](#):
>
> @erlendaasland If I find anything actually missing in What’s New docs, I’ll definitely PR a change. But I very much doubt I will.

If you find anything actually missing in the What’s New doc (or in the docs in general), _it is a documentation bug_ and should as such be fixed. It is super helpful if you file an issue [bug tracker](https://github.com/python/cpython/issues), and even better if you can provide a PR. You can ping me on GitHub (`@erlend-aasland`).

cc. @CAM-Gerlach who has been heavily involved with the 3.11 What’s New doc.

---

<div class="post-metadata">

**Author:** ![RovMan27](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@RovMan27](https://discuss.python.org/u/RovMan27)\
**Post date:** [November 5, 2022, 7:18pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/13 "2022-11-05T19:18:39Z")

</div>

All the above is not encouraging to me. I am a beginner and am trying to find out why the following (an expert’s code) objects to the comma after Exceotions,

try: # try  
import smbus # to import SMbus (a subset of I2C)  
except Exception, err: # incorrect syntax at the comma ?  
print err  
pass

I’m trying to comment each line but “Python All in one for dummies” does not have such an example.  
I don’t know what err is or where it is supposed to be.  
Is the Python syntax continually changing so yesterday’s program will not run?

---

<div class="post-metadata">

**Author:** ![fungi](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/fungi/32/5963_2.png) [@fungi](https://discuss.python.org/u/fungi)\
**Post date:** [November 5, 2022, 7:53pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/14 "2022-11-05T19:53:29Z")

</div>

You’re observing changes in the except clause which were added for  
the Python 3.x series (support for which was backported to some  
later 2.x versions as well) circa 2006 with the introduction of PEP  
3110: [PEP 3110 – Catching Exceptions in Python 3000 | peps.python.org](https://peps.python.org/pep-3110/)

So yes, there are sometimes backward-incompatible changes to the  
interpreter, but in this case it looks like you’re trying to run  
(very) old code written for Python 2.x with a recent 3.x interpreter  
which does not recognize the syntax.

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [November 5, 2022, 8:28pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/15 "2022-11-05T20:28:18Z")

</div>

> [@RovMan27](#):
>
> try: # try  
> import smbus # to import SMbus (a subset of I2C)  
> except Exception, err: # incorrect syntax at the comma ?  
> print err  
> pass
> 
> I’m trying to comment each line but “Python All in one for dummies” does not have such an example.  
> I don’t know what err is or where it is supposed to be.  
> Is the Python syntax continually changing so yesterday’s program will not run?

Yesterday’s program will almost always run. For the most part, changes to Python’s syntax are backward compatible - existing valid code remains valid - so the relevance of “which version introduced this syntax” is usually from the perspective of “if I use this syntax, how old a Python interpreter can I still run this on?”. For example, Python 3.8 introduced this syntax for function headers:

```auto
   def spam(x, /, y):
        ...

```

which will not work on Python 3.7; but code written for 3.7 will still run on 3.8.

The one big exception is that code written for ancient versions of Python - versions older than 2.6, usually - will not always run on modern Pythons. What you’ve come across is a nasty bug magnet that got deprecated and finally removed in Python 3.0; the problem is that these two except statements behave very differently:

```auto
except OSError, ValueError: pass
except (OSError, ValueError): pass

```

So the modern syntax `except Exception as err:` was introduced, and made available in parallel, and then finally the old syntax was removed.

Unfortunately, code this old is going to have other problems as well. I would recommend using the `2to3` modernizer tool to go through it and attempt to update it. On the plus side, Python 3.0 is about the only point where you’ll have that incompatibility, and that was released in 2008, so if you have any code written for a more modern version of Python, you will probably be fine.

---

<div class="post-metadata">

**Author:** ![RovMan27](https://avatars.discourse-cdn.com/v4/letter/r/258eb7/32.png) [@RovMan27](https://discuss.python.org/u/RovMan27)\
**Post date:** [November 5, 2022, 9:23pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/16 "2022-11-05T21:23:22Z")

</div>

Thanks for the replies.  
I got this from GitHub dated 7 years ago which makes it useless to me as a beginner if it chokes a few lines in.  
What exactly is intended by the comma and err?  
except Exception, err:  
I tried lookin it up in [Python.org](http://Python.org) and get pages of stuff that is not relevant.  
I understand that  
except Exception:  
means for an exception do the following. I don’t know what err refers to or how to correct the syntax.  
I will look for the 2 to 3 modernizer tool.

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [November 5, 2022, 9:29pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/17 "2022-11-05T21:29:09Z")

</div>

Simple answer: Write it as `except Exception as err:` instead. For more details, 2to3 is your best bet.

---

<div class="post-metadata">

**Author:** ![jugmac00](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jugmac00/32/1581_2.png) [@jugmac00](https://discuss.python.org/u/jugmac00)\
**Post date:** [November 6, 2022, 5:19pm UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/18 "2022-11-06T17:19:30Z")

</div>

@DavidMertz  
As I have to work with Python 2.7 through 3.11 on a mostly daily basis, I have created [GitHub - jugmac00/python-version-cheat-sheet: about the what and when of new python features](https://github.com/jugmac00/python-version-cheat-sheet)

It does not cover 100% of the changes, but works for me quite well, and it is of course open for pull requests.

---

<div class="post-metadata">

**Author:** ![DavidMertz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidmertz/32/382_2.png) [@DavidMertz](https://discuss.python.org/u/DavidMertz)\
**Post date:** [November 7, 2022, 3:34am UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/19 "2022-11-07T03:34:24Z")

</div>

Fantastic! Thank you.

---

<div class="post-metadata">

**Author:** ![DavidMertz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidmertz/32/382_2.png) [@DavidMertz](https://discuss.python.org/u/DavidMertz)\
**Post date:** [November 7, 2022, 4:01am UTC](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715/20 "2022-11-07T04:01:54Z")

</div>

Sorry, I totally confused which show I meant. Billion Dollar Code was in my “keep watching” queue, but the one with the 2003 Python on a computer screen was [The Playlist (TV series) - Wikipedia](https://en.wikipedia.org/wiki/The_Playlist_(TV_series)). Sorry for that.

 ![PXL_20221107_035909678.MP](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/7/71ad99016d62732c59a29e91bb6e9ae9dd6d41a5.jpeg)

[Next page](https://discuss.python.org/t/guide-to-syntax-changes-by-python-version/20715.md?page=2)
