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.
But you can operate on a list literal as well: You have seen that an element in a list can be any sort of object. A list can contain sublists, which in turn can contain sublists themselves, and so on to arbitrary depth.
Consider this (admittedly contrived) example: There is no limit, short of the extent of your computer’s memory, to the depth or complexity with which lists can be nested in this way.
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.Lists are defined in Python by enclosing a comma-separated sequence of objects in square brackets ( Each of these features is examined in more detail below. (You will see a Python data type that is not ordered in the next tutorial on dictionaries.) Lists that have the same elements in a different order are not the same: Individual elements in a list can be accessed using an index in square brackets.This is exactly analogous to accessing individual characters in a string. Consider the following list: It’s not an accident that strings and lists behave so similarly.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).These types are immutable, meaning that they can’t be changed once they have been assigned.It doesn’t make much sense to think of changing the value of an integer.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.Would your solution work regardless of whether you knew beforehand the length of the string or list (e.g.if you wanted to apply the solution to a set of lists of different lengths)?