Knowledge Card - Common List Operations

Common List Operations

  1. Appending Elements: Add elements to the end of a list.

    • Example: my_list.append(5) adds 5 to my_list.
  2. Removing Elements: Remove specific elements from a list.

    • Example: my_list.remove('apple') removes 'apple' from my_list.
  3. Accessing Elements: Retrieve elements by index.

    • Example: my_list[0] returns the first element.
  4. Slicing Lists: Extract sublists using slicing.

    • Example: my_list[1:3] returns elements at indices 1 and 2.
  5. Modifying Elements: Change elements at specific indices.

    • Example: my_list[0] = 'banana' replaces the first element.