Slicing Lists and Strings


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


Stray text not allowed in code. Comment or remove.

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

Two of these don't look quite right.


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