简体   繁体   中英

Python 3.x print(end = “”) Error

I've tried using both Netbeans and PyCharm, but the same error keeps popping up. The error is when I use end="" as instructed by my tutorial it throws different errors depending on what IDE I'm using. Am I completely typing it incorrectly or can someone give me some advice as to what to do

__author__ = "Kevin"
__date__ = "$May 24, 2015 9:23:37 PM$"

print("Pink", end="")
print("Octopus")

The error code in Netbeans is

No viable alternative at input '='

mismatched input '""' expecting RPAREN
----
(Alt-Enter shows hints)

What's most likely happening here is that you are using a Python3 tutorial, but your interpreter in PyCharm and Netbeans is Python2.

In Python2 print was a statement, whereas in Python3 it's a function .

You should be able to fix this by importing the print function in Python2 from the future module:

from __future__ import print_function
print("Pink", end="")  # now works in Python2

Alternativey, you can update PyCharm to use the Python3 interpreter. See here how to set the interpreter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM