-4

In python 3, I'm tying to print a line without skipping a line as:

print('hello', end='')

And I'm getting this error message:

print('hello', end='')
                  ^
SyntaxError: invalid syntax

What's going on? How do I correct this error?

10
  • Note that I have consulted similar questions without a satisfactory results. Commented Sep 14, 2017 at 17:39
  • 2
    Are you sure you aren't using Python 2? Run import sys; print(sys.version) and see what it prints out. Post back with the results. Commented Sep 14, 2017 at 17:40
  • @vaultah That question's answer did not solve my problem. Commented Sep 14, 2017 at 17:42
  • 1
    what does import sys; print(sys.version) give you? Commented Sep 14, 2017 at 17:43
  • 2
    @StevenRumbalski The code print(sys.version) works for both function and statement print. It won’t work in python3 if some other function has been assigned to the name print, but that also wouldn’t generate this particular error. Commented Sep 14, 2017 at 17:54

1 Answer 1

6

Are you absolutely sure you're using Python 3, and not accidentally invoking Python 2?

~ $ python3
Python 3.6.2 (default, Jul 17 2017, 16:44:45)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello', end='')
hello>>>

~ $ python2
Python 2.7.13 (default, Jul 18 2017, 09:17:00)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello', end='')
  File "<stdin>", line 1
    print('hello', end='')
                      ^
SyntaxError: invalid syntax
>>>
Sign up to request clarification or add additional context in comments.

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.