Python Tips and Tricks

Python Tips and Tricks

  1. How to insert elements in the list?

i)beginning of the list

ii)end of the list

iii)at a particular index

s=[1,2,3,4,5,6]

Adding element at beginning of the list:

s.insert(0,99)

Adding element at the end of the list.

s.append(55)

Adding element at a particular index 3

s.insert(3,77)

List object in memory

Adding element at the beginning of the list.

Inserting an element at a particular index

Adding element at the end of the list

Note:

Adding element at end of the list using insert.

It will push the last element to the end of the list and insert it in that position.

s=[1,2,3]
s.insert(-1,99)
print (s)
Output:
[1, 2, 99, 3]
One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

Buy Me a CoffeeBuy Me a CoffeeBuy Me a Coffee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s