Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Python List pop Function

by suresh

Python List pop function is one of the List functions, which removes an item from the existing list at a user-specified index. In this section, we discuss how to use this Python pop function with a practical example.

The syntax of the Python list pop function is

list_name.pop(index_value)

Remember, the Index position starts at 0 and ends at n-1.

Python List pop example

The below code removes items at index position 1 and 2. You can display the removed item by assigning the value to a new variable. For example, b = a.pop(1) returns 20.

TIP: Please refer to List article to understand everything about Python Lists and List functions.

# Python Pop List Items

a = [10, 20, 30, 40]

print("Original List Items are : ", a)
a.pop(1)
print("List Items are          : ", a)
a.pop(2)
print("List Items are          : ", a)

OUTPUT

Python Pop List Function 1

Python List pop first, second

In this example, we declared a string list. Next, we used pop function to remove items at index position 1 and 2.

# Python Pop List Items

Fruits = ['Apple', 'Orange', 'Banana', 'Kiwi', 'Grape']

print("Original List  : ", Fruits)
Fruits.pop(1)
print("List Items are : ", Fruits)
Fruits.pop(2)
print("List Items are : ", Fruits)

OUTPUT

Python Pop List Function 2

Python pop Example 3

Let me use this pop function on Mixed List. Here, we declared a mixed list of numbers and words. Next, we used the list pop function to remove items at index 1 and 2.

# Python Pop List Items

MixList = ['apple',  1, 'Orange', 5, 'Kiwi', 'Mango']

print("Original List  : ", MixList)
MixList.pop(1)
print("List Items are : ", MixList)
MixList.pop(2)
print("List Items are : ", MixList)

OUTPUT

Python Pop List Function 3

Python Program to Remove List Items

This program removes or pops nested list items at the index position 2 and 3.

# Python Pop List Items

Nested = [[71, 222], [22, 13], [11, 22], [44, 55], [99, 77]]

print("Original List  : ", Nested)
Nested.pop(2)
print("List Items are : ", Nested)
Nested.pop(3)
print("List Items are : ", Nested)

OUTPUT

Python Pop List Function 4

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python numpy concatenate
  • Python numpy Array shape
  • Python pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python Substring
  • Python Programming Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy