There are many ways of doing it
1. pop method – list.pop()
2. slicing – list[1:]
Also Read: Python list remove from front
Example:
# code to understand how to remove first five elements from the list in Python
# www.codewindow.in
a = [100, 111, 122, 132, 144, 789, 785, 458, 45]
b = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
c = ['a', 's', 'd', 'f', 'q', 'w', 'e', 'r', 't', 'y']
d = ["code", "window", "repeat", "win", "good", "local", "place"]
#using pop
for i in range (5):
a.pop(0)
print(a)
#using slicing
b = b[5:]
print(b)
c = c[5:]
print(c)
d = d[5:]
print(d)
Output:
[789, 785, 458, 45]
[15, 16, 17, 18, 19, 20]
['w', 'e', 'r', 't', 'y']
['local', 'place']
Explanation:
Here, pop(0) inside the for loop keeps in poping the index 0, 5 times.
d[ 6:] slices the array from index 5 leaving the element from index 0 to 5.
Follow Us
You Missed
- Apple Is Hiring | For DevOps Engineer – codewindow.in
- L’Oréal is Hiring | Graduate Engineer Trainee – codewindow.in
- Zoho is Hiring | Web Developers – codewindow.in
- TATA Electronics is Hiring | Graduate Engineer Trainee – codewindow.in
- Wipro WILP 2022 – codewindow.in
- Harman is Hiring | Associate Engineer, SW – codewindow.in
- NVDIA Interview Questions – codewindow.in
- Latenview Analytics Overall Interview Questions + Coding Solutions – codewindow.in
- Adobe Overall Interview Questions + Coding Solutions – codewindow.in
- Linkedin Overall Interview Questions + Coding Solutions- codewindow.in
- AXA Insurance is Hiring | Trainee – Global Technology – codewindow.in
- Accenture is Hiring | Data Analyst – codewindow.in
- PWC Interview Questions + Coding Solutions – codewindow.in
- ITC Infotech Overall Interview Questions – codewindow.in
- Texas Instrument Interview Questions + Coding Solutions – codewindow.in
- Deutsche Bank Interview Questions + Coding Solutions – codewindow.in
- Optum – Overall Interview Questions + Coding Solutions – codewindow.in
- Salesforce – Overall Interview Questions + Coding Solutions – codewindow.in
- Morgan Stanly Interview Questions + Coding Solutions – codewindow.in
- Flipkart – Overall Interview Questions + coding Solutions- codewindow.in
- Amazon Interview Questions + Coding Solutions – codewindow.in
- Code Nation – Overall Interview Questions + coding Solutions – codewindow.in
- Bridgei2i – Overall Interview Questions + Coding Solutions – codewindow.in
- De Shaw Interview Questions + Coding Solutions – codewindow.in
- Tiger Analytics – Overall Interview Questions + Coding Solutions – codewindow.in
- Incture Interview Questions +Coding Solutions – codwindow.in
- Commvault Systems Overall Interview Questions + Coding Solution – codewindow.in
- Teg Analytics Overall Interview Questions + Coding Solutions – codewindow.in
- Celebal Tech Interview Questions + Coding Solutions – codewindow.in
- Smart Cube Interview Questions – codewindow.in
- Exxon Mobil Overall Interview Questions – codewindow.in
- Siemens Overall Interview Questions + Coding Solutions – codewindow.in
Also Checkout
- Adobe
- Algorithm
- Amagi
- Amazon Interview Questions
- Aptitude
- Books
- Bridge2i
- Campgemini Interview Questions
- Capgemini Coding Questions
- Capgemini Pseudocode
- Celebal Tech
- code nation
- CodeVita
- Coding Questions
- Cognizant Placement
- commvault Systems
- CTS
- Data Structure and Algorithm
- De Show Interview Questions
- deloitte
- Deutsche Bank Interview questions
- Epam Full Question Paper
- Exxon Mobil interview questions
- filpkart
- Fractal Analytics Interview Questions
- Genpact
- Grab
- GreyB Interview Questions
- Guidance for Accenture
- Gupshup
- HCL Interview Questions
- Hexaware
- HFCL
- HR Questions
- IBM Interview questions
- IBM Questions
- Incture Interview Questions
- Infineon Technologies Interview Questions
- Infosys
- Infosys Interview Questions
- Internship
- Interview Experience
- Interview Questions
- ITC Infotech
- itron
- JECA
- Job Info
- Kantar Interview Questions
- Larsen & Turbo
- Latenview AnalyticsInterview questions
- Lexmark International Interview Questions
- Machine Learning
- Media.net
- Mindtree Interview Questions
- Miscellaneous
- Morgan Stanly Interview Questions
- nagarro
- navi
- NPCI
- NTT Data Interview Questions
- NVDIA
- NVDIA interview questions
- Optum
- PayU
- Persistent INterview Questions
- Programming in C
- Programming in C++
- Programming in JAVA
- Programming in Python
- pseudocode
- PWC Interview Questions
- Quiz
- Razorpay
- Recruiting Companies
- Revature
- salesforce
- Samsung
- Schlumberger
- Seimens
- Slice
- Smart Cube
- Study Material
- Tally Solutions
- tata cliq
- TCS
- TCS NQT
- TCS NQT Coding Questions
- Tech Mahindra Coding Questions
- Tech Mahindra Questions
- Teg Analytics
- Tejas Network Interview Questions
- Texas Instrument Interview Questions
- Tiger Analytics
- Uncategorized
- UnDosTres
- Unstop
- Verbal Ability
- Web Development
- Wipro Coding Questions
- Wipro interview Questions
- Wipro NLTH
- WIpro NLTH Coding Solve
- Zenser
- Zoho Interview Questions