문제

While working my way through Learning Python, this piece of code works fine in Spyder, but breaks in iPython:

# Create a sequence
sequence = ['A', 'B', 'C', 'D']

# Create two variables, the first with 'A', the second with the rest of the letters
Alpha, *allOtherLetters = sequence

When I try to run it in iPython, I get this error:

File "<ipython-input-3-b15e0241bc60>", line 5
    Alpha, *allOtherLetters = sequence
           ^
SyntaxError: invalid syntax

Clearly iPython doesn't like the *, but I don't know what to do about it.

도움이 되었습니까?

해결책

Your IPython probably uses Python 2. foo, *bar = ... only works in Python 3. You can have a look at sys.version_info.major to check which Python version you are using.

Tee solution is to install IPython for Python 3. Since I don't know which distribution you use the easiest way might be creating a Python 3 venv and installing ipython in there using pip install ipython.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top