To get the first element in a Python list, you can use indexing with the index 0.
In this example,
numbers
with integer elements.[0]
.numbers = [10, 20, 30, 40, 50]
first_element = numbers[0]
print(f"First element is: {first_element}")
First element is: 10
In this example,
names
with string elements.[0]
.names = ["Alice", "Bob", "Charlie", "David"]
first_element = names[0]
print(f"First element is: {first_element}")
First element is: Alice
In this tutorial, we learned How to get First Element in a List in Python language with well detailed examples.