course content

Course Content

Introduction to Python

What Is a List?What Is a List?

A list is a data type that allows values or variables of different types to be stored in it, such as numbers, strings, tuples, etc.

To create a list, write a list of comma-separated values/variables in square brackets []. You can convert an iterable object (string, list, tuple) into a list by using the list() function.

For example, we can create a list with US information (country's name, area, and population).

You can access list elements in the same manner as you would string elements by indexing and slicing. For example, we can get both area and population at once. These are the second (index 1) and the third (index 2) elements of the list US_Info. To slice the list, we need to indicate both starting and ending positions separated by a colon : (remember that the boundary itself is not included, and you should set a boundary plus one to the right of the colon). This conveys that we need to use the [1:3] slicing. Consider the example below.

Section 4.

Chapter 1