Login
Congrats in choosing to up-skill for your bright career! Please share correct details.
Home / Blog / Data Science / Python - 3.7
Bharani Kumar Depuru is a well known IT personality from Hyderabad. He is the Founder and Director of AiSPRY and 360DigiTMG. Bharani Kumar is an IIT and ISB alumni with more than 17 years of experience, he held prominent positions in the IT elites like HSBC, ITC Infotech, Infosys, and Deloitte. He is a prevalent IT consultant specializing in Industrial Revolution 4.0 implementation, Data Analytics practice setup, Artificial Intelligence, Big Data Analytics, Industrial IoT, Business Intelligence and Business Management. Bharani Kumar is also the chief trainer at 360DigiTMG with more than Ten years of experience and has been making the IT transition journey easy for his students. 360DigiTMG is at the forefront of delivering quality education, thereby bridging the gap between academia and industry.
A husband and wife are having a discussion over a cup of coffee.
Meaning of a List in Python?
In Python, a list is a collection of different data types. It is structured and allows for replication of access. We use square brackets to indicate that the text is a list. Additionally, a "comma" is used to separate each part.
The behaviour of a list is the same as that of any other array recognised by other computer languages. To use stacks and queues in Python, lists are required. They are changeable types, these lists. Therefore, even after a list is provided, the elements can still be changed.
Click here to explore 360DigiTMG.
Example:
CODE SNIPPET TO CREATE AND PRINT A LIST
OUTPUT:
In the above mentioned example, we have constructed a list called ‘my_List’. In this, all the components are confined within square brackets [ ] and each component is separated by a comma.
The components of several classes can be stacked using this approach in a single list.
One needs have a solid understanding of Python's indexing in order to know which elements to delete from the available List.
TYPES OF INDEXING
We use the index values to ingest a value from a list. The code to extract the letter 'k' from the list containing the letters 'b,g,k,l,m' is provided below.
Both the print declarations will obtain the alphabet ‘k’ from the list.
Python List remove():
Remove Elements from the List using:
The remove() approach discards the first identical component from the list.
The syntax of the remove() method is:
list.remove(element)
remove() specifications
Return Value from remove()
The remove() doesn't restore any value.
Watch Free Videos on Youtube
Here, only the first recurrence of element 'jasmine' is removed from the list.
If a list contains duplicate elements, we can remove the duplicates using the ‘remove()’ method. It removes the first matching element from the list.
Here, we get an error as the list of the flowers doesn't consist of 'lilly'
To summarise, the pop() method removes the item at a provided index and rebounds it; the remove () method removes the first identical equivalent instead of a stated index; and the del operator simply deletes the element at a stated index.
Click here to learn Data Science Course, Data Science Course in Hyderabad, Data Science Course in Bangalore
360DigiTMG - Data Science, Data Scientist Course Training in Bangalore
No 23, 2nd Floor, 9th Main Rd, 22nd Cross Rd, 7th Sector, HSR Layout, Bengaluru, Karnataka 560102
1800-212-654-321
Didn’t receive OTP? Resend
Let's Connect! Please share your details here