methods in python 31.07.2024

arokya_naresh_178a488116e

Arokya Naresh

Posted on August 1, 2024

methods in python 31.07.2024

Methods in LIST

1.Append method

this append method will add items/info at the end of the list

Eg:
package=['Apple','Mango','Banana']
print(package)

package.append('Kiwi')
print(package)

o/p
['Apple', 'Mango', 'Banana']
['Apple', 'Mango', 'Banana', 'Kiwi']

2.insert method

If incase you need to add the items/info in the middle so we can use insert() method

package=['Apple','Mango','Banana']
print(package)

package.insert(1,'Guava') #1 is the index position where we can add items/info
print(package)

o/p
['Apple', 'Mango', 'Banana']
['Apple', 'Guava', 'Mango', 'Banana']

3.Remove method

package=['Apple','Mango','Banana']
print(package)

package.remove('Mango')
print(package)

o/p:
['Apple', 'Mango', 'Banana']
['Apple', 'Banana'

4.Pop method

This POP method will removes last items/info in the list
Also deleted items/info will be returned or assigned to a variiable

Eg:
package=['Apple','Mango','Banana']
print(package)

package.pop()
print(package)

O/P
['Apple', 'Mango', 'Banana']
['Apple', 'Mango']

5.Index method()
To find the Index position we use index() method
Eg:
package=['Apple','Mango','Banana']
print(package)

x=package.index('Mango')
print(x)
o/p
['Apple', 'Mango', 'Banana']
1

6.sort() method

It is used to sort the items/values in the list in Alphabetic order

Eg:
package=['Apple','Mango','Banana']
print(package)

package.sort()
print(package)

O/P
['Apple', 'Mango', 'Banana']
['Apple', 'Banana', 'Mango']

7.reverse() method

It is used to reverse the items/values in the list

Eg
package=['Apple','Mango','Banana']
print(package)

package.reverse()
print(package)

O/P
['Apple', 'Mango', 'Banana']
['Banana', 'Mango', 'Apple']

💖 💪 🙅 🚩
arokya_naresh_178a488116e
Arokya Naresh

Posted on August 1, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024