Ending Up Help



Getting this error:
File "python", line 10
new_word = [1:len(new_word)]
SyntaxError: invalid syntax

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
    word = original.lower()
    first = word[0] 
    new_word = word + first + pyg
    new_word = [1:len(new_word)]
    print 'empty'


This line, you are trying to slice new_word; however the square brackets are not being applied to a string. You need to put the string object you want to apply the slicing to directly before it.


I still don't quite understand, could you please elaborate? Thanks. The lesson instructions specifically used that syntax.


[1:] # the slicing is done straight after the string
a = "string"
a[1:] # again, done straight after the string
a = [1:] # you are not doing it to the string.  You are trying to define
         # a with the equals sign, which is stopping the slicing on the string.
a = a[1:] # now we are redefining a as a sliced at index position 1.


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