How to solve the error when write end=‘ ’ in print()?

Yeshin Lee
2 min readOct 5, 2022

--

The following error occurs when adding end=‘ ’ to the print function. end=‘ ’ is put space next to the output value.

This problem is related to the Python version. The Python interpreter version currently in use is 2.7, print in Python 2 is tuple as argument.(It don’t take keyword arguments.) Upgrade version to 3 and it will be resolved.

If you don’t want to change the version, add the following command at the top of the script.

from __future__ import print_function

The official document describes __future_ module as follows.

A future statement is a directive to the compiler that a particular module should be compiled using syntax or semantics that will be available in a specified future release of Python. The future statement is intended to ease migration to future versions of Python that introduce incompatible changes to the language. It allows use of the new features on a per-module basis before the release in which the feature becomes standard.

This makes the print function of Python 3 available in Python 2.6+.

--

--

Yeshin Lee
Yeshin Lee

No responses yet