Update python lists and tuples

This commit is contained in:
Angelos Chalaris
2020-08-08 14:58:02 +03:00
parent 31880253dd
commit 7e116e273c

View File

@ -13,7 +13,6 @@ excerpt: Learn how Python's lists and tuples are different and level up your cod
- Contained elements are mutable (can be changed after creation)
- Lists have a variable length
- A list takes up more memory than a tuple
- Can only store homogenous elements (of the same type)
**Tuples**
@ -21,10 +20,9 @@ excerpt: Learn how Python's lists and tuples are different and level up your cod
- Contained elements are immutable (cannot be changed after creation)
- Tuples have a fixed length
- A tuple takes up less memory than a list
- Can store heterogenous elements (of different types)
**When to use each one**
Lists provide a more accessible API and should be used whenever similar types of objects need to be stored and are expected to change over the course of the application's execution. On the other hand, tuples should be used for immutable and heterogenous data, behaving more like constants than variables.
Lists provide a more accessible API and should be used whenever similar types of objects need to be stored and are expected to change over the course of the application's execution. On the other hand, tuples should be used for immutable data, behaving more like constants than variables.
**Image credit:** [Hasan Almasi](https://unsplash.com/@hasanalmasi?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/code?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)