【问题标题】:end="" parameter doesn't work on Sublimetext 3end="" 参数在 Sublime Text 3 上不起作用
【发布时间】:2020-12-03 21:22:52
【问题描述】:

我尝试在 sublimetext 3 中使用 print("hello", end='') 并且它说语法无效 这是代码:

y = 0
while y < 14:
    y+=1
    for i in range(1,4):
        y+=1
print(y, end="")

其他一切正常。

【问题讨论】:

  • 你真的在使用 Python 3 吗? Sublime Text 知道吗?
  • 实际上,您几乎肯定会与 Python 内置构建系统的执行方式相冲突 python,在许多系统上是 Python 2 而不是 Python 3。
  • @OdatNurd 谢谢你,我确实在使用 python2。我为 python 3 构建了一个系统,它可以工作。

标签: python python-3.x printing sublimetext3


【解决方案1】:

在 python 3 中,您不能更改 for 循环使用的变量。 这是您的代码的一个更好的版本:

x = 0
y = 0
while x < 14:
    x += 1
    for i in range(1, 4):
        y += 1
print(x + y, end="")

【讨论】:

  • 1.这是一个while循环,它不会改变y。您的代码与 OP 的不同。 2.你可以改变for循环使用的变量,但不推荐这样做,你应该知道你在做什么(例如创建它的副本)。
猜你喜欢
  • 2014-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-14
相关资源
最近更新 更多