Summary

  1. Lists are mutable, meaning you can modify them after creation by adding, removing, or changing elements.
  2. Lists have dynamic sizing, automatically resizing as elements are added or removed, unlike fixed-size arrays in other languages.
  3. Lists can store heterogeneous data types, including integers, strings, and objects, offering great flexibility.
  4. Lists maintain a defined order, with elements arranged in a specific sequence that remains consistent unless explicitly changed.
  5. Elements are accessed via zero-based indexing, where the first element is at index 0, the second at index 1, and so on.
  6. Negative indexing is supported, allowing access to elements from the end of the list, with -1 referring to the last element.
  7. Lists can contain duplicate values, enabling the same value to appear multiple times within the same list.
  8. The list() function can be used to create lists, either empty or by converting other iterables like strings or tuples.
  9. You can access sublists using slicing notation, specifying start, stop, and step indices within square brackets (e.g., list[start:stop]).
  10. List comprehensions provide a concise way to create lists, using an expression and for-loop within square brackets.
  11. The append() method adds elements to the end of the list, increasing the list's size dynamically.
  12. The insert() method allows adding elements at a specific index, shifting subsequent elements to the right.
  13. Elements can be removed by value using the remove() method, which deletes the first matching element found.
  14. Lists can be sorted in place using the sort() method, which arranges elements in ascending or descending order.
  15. The len() function returns the number of elements in a list, providing a quick way to determine its size.
  16. Tuples are immutable, meaning their contents cannot be changed after creation.
  17. Tuples maintain a defined order, with elements arranged in a specific sequence that remains consistent.
  18. Tuples can store heterogeneous data types, including integers, strings, lists, and other tuples.
  19. Elements in tuples are accessed via zero-based indexing, similar to lists.
  20. Negative indexing is supported, allowing access to elements from the end of the tuple.
  21. Tuples provide data integrity, ensuring that the data remains constant throughout the program's execution.
  22. Tuples are hashable, making them usable as keys in dictionaries and elements in sets.
  23. Slicing allows access to a range of elements within tuples, specifying start, stop, and step indices.
  24. Tuples are useful for storing read-only data, ensuring stability and preventing accidental modification.