Add last snippet
This commit is contained in:
17
snippets/last.md
Normal file
17
snippets/last.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: last
|
||||||
|
tags: list,beginner
|
||||||
|
---
|
||||||
|
|
||||||
|
Returns the last element in a list.
|
||||||
|
|
||||||
|
use `lst[-1]` to return the last element of the passed list.
|
||||||
|
|
||||||
|
```py
|
||||||
|
def last(lst):
|
||||||
|
return lst[-1]
|
||||||
|
```
|
||||||
|
|
||||||
|
```py
|
||||||
|
last([1, 2, 3]) # 3
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user