How to Get First 2, 3, 4, 5, 10, etc Elements from List in Python?

By Hardik Savani October 30, 2023 Category : Python

Hello Folks,

This post will give you an example of python get first 10 elements from list. If you have a question about python get first 4 elements from list then I will give a simple example with a solution. In this article, we will implement a how to get first 2 elements from list in python. This article will give you a simple example of how to get first 3 element from list in python.

I will give you 5 examples of how to get two, three, four, five, ten elements from list. you can view one by one example that way you can use it what you need. we will use [0:N] to get get elements. let's see the examples:

You can use these examples with python3 (Python 3) version.

Example: Python Get Get 2 Elements from List

main.py

# Create New List with Item
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  
# Python Get Get 2 Elements from List
newList = myList[0:2]
  
print(newList)

Output:

[1, 2]

Example: Python Get Get 3 Elements from List

main.py

# Create New List with Item
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  
# Python Get Get 3 Elements from List
newList = myList[0:3]
  
print(newList)

Output:

[1, 2, 3]

Example: Python Get Get 4 Elements from List

main.py

# Create New List with Item
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  
# Python Get Get 4 Elements from List
newList = myList[0:4]
  
print(newList)

Output:

[1, 2, 3, 4]

Example: Python Get Get 5 Elements from List

main.py

# Create New List with Item
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  
# Python Get Get 5 Elements from List
newList = myList[0:5]
  
print(newList)

Output:

[1, 2, 3, 4, 5]

Example: Python Get Get 10 Elements from List

main.py

# Create New List with Item
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
  
# Python Get Get 10 Elements from List
newList = myList[0:10]
  
print(newList)

Output:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

I hope it can help you...

Tags :
Shares