What is wrong with my code?
Gary Herron
gherron at islandtraining.com
Sun Oct 23 13:04:45 EDT 2011
On 10/23/2011 03:08 AM, Chris Rebert wrote:
> On Sun, Oct 23, 2011 at 3:03 AM, apometron
> <apometron.listas.cinco at gmail.com> wrote:
>> import os
>> nome = sys.argv[1]
> You did not `import sys`, so you'll get a NameError there.
>
>> final = nome
>> for i in nome:
>> print i
>> if nome[i] = "_":
>> final[i] = " "
> Strings aren't mutable in Python; you can't assign to slices of them.
> So you'll get a TypeError on the previous line.
>
> Cheers,
> Chris
Also, the statement
for i in nome:
does not loop through indices, but rather it loops through the actual
characters of the string.
Gary Herron
More information about the Python-list
mailing list