List and slicing


#1

animals = "catdogfrog"
cat = animals[:3] # The first three characters of animals
dog = animals[3:4:5] # The fourth through sixth characters
frog = animals[5:] # From the seventh character to the end

Hi,
here I get an error message saying that Idog only outputs 'd' instead of 'dog'.
How come?


#2

here:

dog = animals[3:4:5] # The fourth through sixth characters

specifying 3 values for list slicing, like you did here you, you have:
3 start value
4 stop value
streps/strides 5

that can't be right, why would you take steps of 5? You just need two values in your list slicing, start and stop


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.