What's wrong with this?


#1

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
else:
print 'empty'
Please help???


#2

Assign this back onto new_word.


#4

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


#5

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)]

#7

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