Get The Most Affordable Hosting in the World!

Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.

Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!

Get Started Now!

The array class defines two methods with the help of which we can remove an element from the array. It has remove() and pop() methods

array.remove() Method

The remove() method removes the first occurrence of a given value from the array

Syntax

array.remove(v)

Parameters

  • v − The value to be removed from the array

Example

 
import array as arr a = arr.array('i', [1, 2, 1, 4, 2]) a.remove(2) print (a)

It will produce the following output −

array('i', [1, 1, 4, 2])

array.pop() Method

The pop() method removes an element at the specified index from the array, and returns the removed element.

Syntax

array.pop(i)

Parameters

  • i − The index for the eminent to be removed. The method returns element at ith position after removal.

Example

 
import array as arr a = arr.array('i', [1, 2, 1, 4, 2]) a.pop(2) print (a)

It will produce the following output −

array('i', [1, 2, 4, 2])



The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.
這篇文章有幫助嗎? 1 用戶發現這個有用 (1 投票)

Powered by WHMCompleteSolution