0

Why is "in" faster than "==" in Python3???

My code:

>>> timeit.timeit("a='ssss'; a=='ssss'")
0.029274068772792816

>>> timeit.timeit("a='ssss'; a in {'ssss'}")
0.02768799662590027
cty
  • 9
  • 2
  • 6
    How many times have you repeated this experiment? – Mohsin Nov 27 '19 at 06:28
  • 4
    Possible duplicate of [Why is 'x' in ('x',) faster than 'x' == 'x'?](https://stackoverflow.com/questions/28885132/why-is-x-in-x-faster-than-x-x) – Arun Palanisamy Nov 27 '19 at 06:36
  • I'm just gonna copy one sentence from the questions' comments provided by @ArunPalanisamy: "If you're writing in Python and you choose one construct over another for speed, you're doing it wrong." by Veky. – Asunez Nov 27 '19 at 08:20

0 Answers0