this post was submitted on 23 Oct 2025
20 points (85.7% liked)
Python
7589 readers
6 users here now
Welcome to the Python community on the programming.dev Lemmy instance!
📅 Events
Past
November 2023
- PyCon Ireland 2023, 11-12th
- PyData Tel Aviv 2023 14th
October 2023
- PyConES Canarias 2023, 6-8th
- DjangoCon US 2023, 16-20th (!django 💬)
July 2023
- PyDelhi Meetup, 2nd
- PyCon Israel, 4-5th
- DFW Pythoneers, 6th
- Django Girls Abraka, 6-7th
- SciPy 2023 10-16th, Austin
- IndyPy, 11th
- Leipzig Python User Group, 11th
- Austin Python, 12th
- EuroPython 2023, 17-23rd
- Austin Python: Evening of Coding, 18th
- PyHEP.dev 2023 - "Python in HEP" Developer's Workshop, 25th
August 2023
- PyLadies Dublin, 15th
- EuroSciPy 2023, 14-18th
September 2023
- PyData Amsterdam, 14-16th
- PyCon UK, 22nd - 25th
🐍 Python project:
- Python
- Documentation
- News & Blog
- Python Planet blog aggregator
💓 Python Community:
- #python IRC for general questions
- #python-dev IRC for CPython developers
- PySlackers Slack channel
- Python Discord server
- Python Weekly newsletters
- Mailing lists
- Forum
✨ Python Ecosystem:
🌌 Fediverse
Communities
- #python on Mastodon
- c/django on programming.dev
- c/pythorhead on lemmy.dbzer0.com
Projects
- Pythörhead: a Python library for interacting with Lemmy
- Plemmy: a Python package for accessing the Lemmy API
- pylemmy pylemmy enables simple access to Lemmy's API with Python
- mastodon.py, a Python wrapper for the Mastodon API
Feeds
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Except if
__iadd__doesn't exist on the type, then__add__is called. The variable is always reassigned. Quick example:What is printed?
Thanks. I didn't know: https://memory-graph.com/#code=x+%3D+%280%2C+%5B1%2C+2%5D%29%0Atry%3A%0A++++x%5B1%5D+%2B%3D+%5B3%5D++%23+calls+list.__iadd__%2C+then+reassigns+x%5B1%5D%0Aexcept+TypeError+as+e%3A%0A++++print%28e%29%0A%0Ax+%2B%3D+%284%2C%29++%23+calls+tuple.__add__%2C+then+reassigns+x%0A%0Aprint%28x%29%0A%0A%0Aclass+MyClass%3A%0A++++%0A++++def+__add__%28self%2C+other%29%3A%0A++++++++print%28%27__add__%27%29%0A++++++++%0A++++%23def+__iadd__%28self%2C+other%29%3A%0A++++%23++++print%28%27__iadd__%27%29%0A%0Aa+%3D+MyClass%28%29%0Ab+%3D+MyClass%28%29%0Aa+%2B%3D+b++%23+calls+__add__+if+__iadd_+doesn%27t+exist%0A&play=