繁体   English   中英

打印语句中的end关键字在Python UBUNTU中不起作用

[英]End keyword in print statement is not working in Python UBUNTU

与print语句一起使用的end关键字在我的PYTHON UBUNTU中不起作用(无论是在sublime还是在pycharm ce中,也没有在终端中。甚至都无法导入sys和time

我也尝试导入sys和时间并使用time.sleep(),sys.stdout.write(),sys.stdout.flush()

这是代码

print("Hi",end=" ")
print("hello")

错误信息:

file "/home/ansh/Desktop/fun.py", line 3
print("Hello", end = " ")
                    ^
SyntaxError: invalid syntax
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/home/ansh/Desktop/fun.py"]
[dir: /home/ansh/Desktop]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:                /bin:/usr/games:/usr/local/games:/snap/bin]

看起来您正在使用Python 2.x而不是3.x。

在Python 2.x中可以使用以下方法实现相同的目的:

print "Hi", 
print "hello"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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