How to get the last element in a list? | Python

Опубликовано: 29 Октябрь 2024
на канале: CyberTodd
544
16

To access the last element in any list, you simply have to target the index of negative 1. Example:

a = ['Hi', 2, 'times', '.']
print(a[-1])

Output:
.

-------------------------Subscribe----------------------------
• If you like to see a variety of fun and interactive projects written in Python
• If you love ☕ and 🐶 WAIT! - Yeah! Definitely, coffee and dogs!
-----------------------------------------------------------------------

-------------------------Socials----------------------------
• Twitter:   / iftodd1  
• Facebook:   / iftodd  
• Instagram:   / if_todd  
------------------------------------------------------------------

-------------------------Support----------------------------
You can support me here:   / if_todd  
--------------------------------------------------------------------

How to get the last element in a list? | Python #shorts #python #lists