【问题标题】:How does this syntax work: print("Hello", end="")这个语法是如何工作的: print("Hello", end="")
【发布时间】:2016-10-31 21:11:23
【问题描述】:

在 python 中,我发现我在打印后不能有新行:print("something", end=""),你说end=something 的这种语法是如何工作的,以及你希望如何以及为什么要在你自己的函数声明中使用它. 对不起,如果这是重复的,但我不知道这个语法叫什么。

【问题讨论】:

  • 你试过在 python 文档中查找它吗?

标签: python function syntax


【解决方案1】:

它告诉print 函数以空字符串而不是换行符结束行。

https://docs.python.org/3/whatsnew/3.0.html

【讨论】:

    【解决方案2】:

    这种语法称为关键字参数(或命名参数)。这在官方 Python 教程中有解释:https://docs.python.org/3/tutorial/controlflow.html#keyword-arguments

    打印文档在这里。 https://docs.python.org/3/library/functions.html#print

    如果您在阅读这些文档后仍有疑问,请随时提问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      相关资源
      最近更新 更多