What's wrong with this?


It's showing me error and I can't figure out why.
It says:

File "python", line 9
new_ word[1:len(new_word)]
SyntaxError: invalid syntax

My code:
pyg = 'ay'

original = raw_input('Enter a word:')

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


Assign this back onto new_word.


I am having the same problem and I don't quite understand your answer, can you please give an example of what you mean? I'm afraid I'm a bit lost, thanks


We can modify or slice a string, but not in place. However we can reassign the new string the same variable that it came from...

a = a[1:len(a)]


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