How to Get First Element of List in Python?
This example is focused on python get first element from list. We will use python get first element of list of lists. Iâ€™m going to show you about how to get first element of list in python. this example will help you how to get first n elements of a list in python.
There are a few ways to get the first element from the list in python. You could use either return only value in string or return array of the first value. so let's see the below examples:
You can use these examples with python3 (Python 3) version.
let's see a below a simple example with output:
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Get First Element firstElem = myList print(firstElem)
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Get First Element firstElem = myList[:1] print(firstElem)
I hope it can help you...
We are Recommending you
- How to Remove First Element from List in Python?
- Python List Remove Element by Value Example
- Python List Remove Element by Index Example
- How to Get All Files from Directory in Python?
- Python Delete Files Matching Pattern Example
- Python Delete Folder and Files Recursively Example
- Python Delete Files with Specific Extension Example
- Python Delete Directory if Exists Example
- Python Post Request with Json File Example
- Python Copy File From one Directory to Another Example
- How to Check if Today is Sunday or not in Python?