Answers for "python list get last n elements"

3

get last element of a list python

a = [1, 2, 3, 4]
print(a[-1])
#prints: 4

print(a[-2])
#prints: 3
Posted by: Guest on January-16-2021
1

python print last 3

message = iloveyouchina
#get last x words
#for example x = 3
print(message[-3:]
Posted by: Guest on July-09-2020
1

python get last item in a list

my_list = ["I", "Love", "Python"]
last_item_in_list = my_list[-1]
# last_item_in_list = "Python"
Posted by: Guest on January-15-2021

Code answers related to "python list get last n elements"

Python Answers by Framework

Browse Popular Code Answers by Language