Slicing Lists and Strings


#1

Oops, try again. Your code looks a bit off. See the console window for the full error message.

File "python", line 5
If your list slice includes the v
^
SyntaxError: invalid syntax


animals = "catdogfrog"
cat  = animals[:3]   # The first three characters of animals
dog  = animals[4:6]               # The fourth through sixth characters
frog = animals[7:]             # From the seventh character to the endh last items
If your list slice includes the v


#3

Stray text not allowed in code. Comment or remove.

>>> animals = "catdogfrog"
>>> cat  = animals[:3]
>>> cat
'cat'
>>> dog  = animals[4:6]
>>> dog
'og'
>>> frog = animals[7:]
>>> frog
'rog'
>>>

Two of these don't look quite right.


#4

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