Are tuples more efficient than lists in Python?
问题 Is there any performance difference between tuples and lists when it comes to instantiation and retrieval of elements? 回答1: The dis module disassembles the byte code for a function and is useful to see the difference between tuples and lists. In this case, you can see that accessing an element generates identical code, but that assigning a tuple is much faster than assigning a list. >>> def a(): ... x=[1,2,3,4,5] ... y=x[2] ... >>> def b(): ... x=(1,2,3,4,5) ... y=x[2] ... >>> import dis >>>