+ 1
can anyone tell me the syntax to print last element of a list by list slice method
4 odpowiedzi
+ 5
print(list[-1])
+ 2
Here is some stuff on slices
https://code.sololearn.com/cXNzv56rgiyL
+ 1
CarrieForle thanks for the help
0
Rahul Prasad sorry, but as I know slice for list is used in JavaScript. In Python, however, we use pop()!
If you're talking about JS:
console.log(array.slice(-1));
But if you're talking about Python :
print(array.pop())
Happy programming! :)