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: <br /> <br />

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