0

I found this Python code online:

table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
>>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; '
...       'Dcab: {0[Dcab]:d}'.format(table))

This executes perfectly to give me Jack: 4098; Sjoerd: 4127; Dcab: 8637678.

But when I tried removing the three dots and running the code I got an error:

table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
>>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; Dcab: {0[Dcab]:d}'.format(table))
File "<ipython-input-53-2065564231a1>", line 3
    >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; Dcab: {0[Dcab]:d}'.format(table))
     ^
SyntaxError: invalid syntax

Why is this happening?

What do the three dots mean?

10
  • 1
    It's the continuation of a line indicator when using ipython etc; Commented Jun 25, 2020 at 7:15
  • It's not part of the code, just as the >>> isn't part of the code. Commented Jun 25, 2020 at 7:16
  • but why didn't the code work when I removed the dots and moved it to a single line Commented Jun 25, 2020 at 7:17
  • This probably indicates the indentation when you execute python from command prompt. Plz look into this docs.python.org/2.0/ref/indentation.html Commented Jun 25, 2020 at 7:17
  • I think the syntax error is indicating the >>>?! Because that's not part of the code. The ... are irrelevant. The problem is that you're trying to execute code including the >>>. Commented Jun 25, 2020 at 7:18

2 Answers 2

1

From the documentation:

When commands are read from a tty, the interpreter is said to be in interactive mode.

In this mode it prompts for the next command with the primary prompt, usually three greater-than signs (>>>); for continuation lines it prompts with the secondary prompt, by default three dots (...).

The interpreter prints a welcome message stating its version number and a copyright notice before printing the first prompt

Sign up to request clarification or add additional context in comments.

Comments

0

The code works when you remove the >>> from it. the >>> was giving the error.

The code also works if you use >>> in the first line and ... in the next line. Jupyter notebooks was used to run this code.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.