Ashwin Radhakrishnan
Ashwin Radhakrishnan

Reputation: 19

what do the three dots in this line of Python code mean?

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?

Upvotes: 0

Views: 1541

Answers (2)

Red
Red

Reputation: 27577

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

Upvotes: 1

Ashwin Radhakrishnan
Ashwin Radhakrishnan

Reputation: 19

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.

Upvotes: 0

Related Questions