Why use tuples instead of objects?

后端 未结 10 2011
别那么骄傲
别那么骄傲 2020-12-24 05:29

The codebase where I work has an object called Pair where A and B are the types of the first and second values in the Pair. I find this object to be offensive, because it g

10条回答
  •  悲哀的现实
    2020-12-24 05:45

    Tuples are used all the time in Python where they are integrated into the language and very useful (they allow multiple return values for starters).

    Sometimes, you really just need to pair things and creating a real, honest to god, class is overkill. One the other hand, using tuples when you should really be using a class is just as bad an idea as the reverse.

提交回复
热议问题