Python Gotchas

Naren Ravi (~naren)




Python aims to be a clean and consistent language that avoids surprises. However, there are few edge cases that can be confusing to newcomers or sometimes even the experienced ones. If you are not aware of these gotchas, you might conclude that the language is poorly designed when you come across it in production. Some cases are intentional but can be surprising, for example

>>> hash(2)
>>> hash(1)
>>> hash(-2)
>>> hash(-1)
-2      # really?


# a = a + b is not equal to a+=b in all cases
>>> a = [1, 2, 3]
>>> id(a)
>>> a += [4]
>>> id(a)
>>> a = a + [5]
>>> id(a)


>>> float("abc")-float("abc")
ValueError: could not convert string to float: abc
>>> float("inf")-float("inf")

It might seem strange at first glance, but it makes more sense once you are aware of the underlying reasons for the surprises. This will be an interactive talk where I will be talking about these gotchas with lot of examples and the audience will be able to guess what/why python behaves the way it does.


Basic python.

Content URLs:

Presentation (Draft) :

Speaker Info:

Naren is a back-end engineer who works for MAD STREET DEN in creating and implementing scalable architecture for Artificial Intelligence / Computer Vision products. He loves coding in python. He is also an electronics hobbyist and ardent endurance cyclist.

Speaker Links:

Section: Core Python
Type: Talks
Target Audience: Beginner
Last Updated:

I wanted to check if you have previously presented on this topic at any local meetup. This is an interesting proposal and often, these form of proposals evolve if the speaker has been discussing these over a period of time.

sankarshan mukhopadhyay (~sankarshan)

Hey Sankarshan, thanks for asking. I have discussed about these topics with my colleagues and friends many times. Previously i have given a bunch of talks in few colleges and other meetups. My previous talks revolved around IoT and python mostly. In next month's ChennaiPy meetup, i will be giving a talk on the above proposed topic.

Naren Ravi (~naren)

Login to add a new comment.