PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Written By

Python Get Last Element of List Example

Python Get Last Element of List Example

Hi,

There are a few ways to get the last element from the list in python. You could use either by key with "-1" or using "pop()" function. so let's see the below examples:

let's see a below a simple example with output:

Example 1:

main.py

myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  
# Get Last Element
lastElem = myList[-1]
  
print(lastElem)

Output:

Sat

Example 2:

main.py

myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  
# Get Last Element
lastElem = myList.pop()
  
print(lastElem)

Output:

2

I hope it can help you...

Comments (0)

loading comments