簡體   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