We create a list by putting values inside square brackets and separating the values with commas: Data which can be modified in place is called mutable, while data which cannot be modified is called immutable. This does not mean that variables with string or number values are constants, but when we want to change the value of a string or number variable, we can only replace the old value with a completely new value.
Lists and arrays, on the other hand, are mutable: we can modify them after they have been created.
If we make a list and (attempt to) copy it then modify in place, we can cause all sorts of trouble: Subsets of lists and strings can be accessed by specifying ranges of values in brackets, similar to how we accessed ranges of positions in a Num Py array.
This is commonly referred to as “slicing” the list/string.
We can change individual elements, append new elements, or reorder the whole list.
For some operations, like sorting, we can choose whether to use a function that modifies the data in-place or a function that returns a modified copy and leaves the original unchanged. If two variables refer to the same list, and you modify the list value, it will change for both variables!You should consider both of these aspects when writing your code.While modifying in place, it is useful to remember that Python treats lists in a slightly counter-intuitive way.When you’re finished, you should have a good feel for when and how to use these object types in a Python program.In short, a list is a collection of arbitrary objects, somewhat akin to an array in many other programming languages but more flexible. The order in which you specify the elements when you define a list is an innate characteristic of that list and is maintained for that list’s lifetime.But what if we want to take a subset of entries that aren’t next to each other in the sequence?You can achieve this by providing a third argument to the range within the brackets, called the Notice that the slice taken begins with the first entry in the range, followed by entries taken at equally-spaced intervals (the steps) thereafter.loop is a way to do operations many times, a list is a way to store many values.Unlike Num Py arrays, lists are built into the language (so we don’t have to load a library to use them).If you want a different integer, you just assign a different one. Strings are reducible to smaller parts—the component characters. The list is the first mutable data type you have encountered.It might make sense to think of changing the characters in a string. Once a list has been created, elements can be added, deleted, shifted, and moved around at will.