Jul 30, 2024
[ ]
and separate values with commas.
nums = [25, 12, 636, 95, 14]
print(nums)
.nums[0]
returns the first element (25).nums[-1]
returns 14.nums[2:]
retrieves third element to the end.values = [9.5, 'name', 25]
mil = [nums, names]
append(value)
: Adds a value at the end.insert(index, value)
: Inserts a value at a specific index.remove(value)
: Removes the first occurrence of the specified value.pop(index)
: Removes and returns the item at the specified index (or last item if no index is provided).clear()
: Removes all items from the list.extend([other_values])
: Adds multiple elements to the end of the list.nums.append(45)
nums.insert(2, 2077)
nums.remove(14)
pop
:
nums.pop(1)
del
to remove a range of elements:
del nums[2:] # Deletes from index 2 to end
min(nums)
- returns minimum value.max(nums)
- returns maximum value.sum(nums)
- returns total sum.sort()
- sorts the list in ascending order.