⚖ Comparison Table for Python Data Structures
| Data Structure | Make With | Ordered? | Mutable? | Can have duplicates? | Examples |
|---|---|---|---|---|---|
| String | '' or "" or str() | Yes | No | Yes | "CSW8", str(3.75) |
| List | [ ] or list() | Yes | Yes | Yes | [12, 9.8], list("ABCDEF") |
| Tuple | ( ) or tuple() | Yes | No | Yes | ('Tu', 'Th'), tuple(['Tu', 'Th']) |
| Dictionary | { } or dict() | No | Yes | keys: No, values: Yes | {1: "Mon", 2: "Tue"}, dict(Mon = 1, Tue = 2) |
| Set | { } or set() | No | Yes | No | {"Jan", "Feb", "Feb"}, set("ABCDEF") |
The constructor functions are usually used to create an empty object or a new object of that type with the input values of a different type converted into its elements.
Acknowledgements
Specials thanks to Allison Horst for creating the initial table.