Using .join() - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Using .join() (/thread-27896.html) |
Using .join() - extricate - Jun-26-2020 Hi there, I'm supposed to join up the string by entering an input. I can't seem to get it to work, I suspect the separator i input might not be a string. Any advice? phrase_words = ['Jack', 'and', 'Jill', 'went', 'up', 'the', 'hill', 'To', 'fetch', 'a', 'pail', 'of', 'water'] separator = input("Enter: ") print(separator.join(phrase_words))Thanks RE: Using .join() - ndc85430 - Jun-26-2020 (Jun-26-2020, 06:40 AM)extricate Wrote: I can't seem to get it to work, I suspect the separator i input might not be a string. Any advice? What exactly doesn't work? input returns a string, so I don't know what you mean.
RE: Using .join() - extricate - Jun-26-2020 Weird, I put the code into visualizer and it worked. Guess my jupyter has some problem running the code The error code was: Enter: - File "<string>", line 1 & ^ SyntaxError: unexpected EOF while parsing RE: Using .join() - ndc85430 - Jun-26-2020 Are you by any chance using Python 2? I suspect so, as input behaves like eval in Python 2, so it's trying to evaluate what you enter as Python code. If you are using Python 2, why? It has been end of life since the beginning of the year.
|