concept Python Tutor in category python

appears as: Python Tutor, Python Tutor
Python Workout: 50 ten-minute exercises

This is an excerpt from Manning's book Python Workout: 50 ten-minute exercises.

You can work through a version of this code in the Python Tutor at http://mng.bz/ vx1q.

Figure 3.1 Individual elements (from the Python Tutor)

When you retrieve a single element from a sequence (figure 3.1), you can get any type at all. String indexes return one-character strings, but lists and tuples can contain anything. By contrast, when you use a slice, you’re guaranteed to get the same type back--so a slice of a tuple is a tuple, regardless of the size of the slice or the elements it contains. And a slice of a list will return a list. In figures 3.2 and 3.3 from the Python Tutor, notice that the data structures are different, and thus the results of retrieving from each type will be different.

Figure 3.2 Retrieving slices from a list (from the Python Tutor)
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest