Python Gotchas

Naren Ravi (~naren)


30

Votes

Description:

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)
2
>>> hash(1)
1
>>> hash(-2)
-2
>>> hash(-1)
-2      # really?

--------------------------------------

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

--------------------------------------

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

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.

Prerequisites:

Basic python.

Content URLs:

Presentation (Draft) : https://www.slideshare.net/secret/DWuUiEp15wL0Bn

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:

https://github.com/makernaren <br /> https://twitter.com/makernaren <br /> http://in.linkedin.com/in/makernaren

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