top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python List

Writer: Aizaz KhanAizaz Khan

A list is a container which holds comma-separated values (items or elements) between square brackets where items or elements need not all have the same type.

In general, we can define a list as an object that contains multiple data items (elements). The contents of a list can be changed during program execution. The size of a list can also change during execution, as elements are added or removed from it.




Examples of lists:

  • numbers = [10, 20, 30, 40, 50]

  • names = ["Sara", "David", "Warner", "Sandy"]

  • student_info = ["Sara", 1, "Chemistry"]

Create a Python list




Following list contains all string:



Following list contains a string, an integer and a float values:






use + operator to create a new list that is a concatenation of two lists and use * operator to repeat a list. See the following statements.





List indices:

List indices work the same way as string indices, list indices start at 0. If an index has a positive value it counts from the beginning and similarly it counts backward if the index has a negative value. As positive integers are used to index from the left end and negative integers are used to index from the right end, so every item of a list gives two alternatives indices. Let create a list called color_list with four items. color_list=["RED", "Blue", "Green", "Black"]

ItemREDBlueGreenBlackIndex (from left) 0 1 2 3Index (from right)-4-3-2-1

If you give any index value which is out of range then interpreter creates an error message. See the following statements.





Add an item to the end of the list:






Insert an item at a given position:






Modify an element by using the index of the element:







Remove an item from the list:




Remove all items from the list:




Remove the item at the given position in the list, return it





Slicing list:

This refers to the items of a list starting at index startIndex and stopping just before index endIndex. The default values for list are 0 (startIndex) and the end (endIndex) of the list. If you omit both indices, the slice makes a copy of the original list.








Sort the items of the list in place:





 
 

1 Comment


Data Insight
Data Insight
Oct 06, 2021

Do not embed code snapshot. Use any of the methods describe here https://linktrest.io/EmbedCode to embed code in your blog posts.

Like

COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page