gpt4 book ai didi

ipython - 如果我在 iPython 中输入/,为什么会得到空元组?

转载 作者:行者123 更新时间:2023-12-04 18:05:47 25 4
gpt4 key购买 nike

打开 iPython 并输入:

/

按 Enter 并想知道结果:
()

你不能分配它,我猜它与 shell 功能有关。

编辑:

您可以将其分配给:
 p = Out[xx]

但不是直接:
 p = / 

会给:
SyntaxError

它确实是一个空元组。

最佳答案

这是可调用对象/名称的便利功能。它不是空元组,而是括号完成。来自 iPython 的帮助系统 ( ? ):

  • Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)

    1. Auto-parentheses

      Callable objects (i.e. functions, methods, etc) can be invoked like this (notice the commas between the arguments)::

      In [1]: callable_ob arg1, arg2, arg3

      and the input will be translated to this::

      callable_ob(arg1, arg2, arg3)

      This feature is off by default (in rare cases it can produce undesirable side-effects), but you can activate it at the command-line by starting IPython with --autocall 1, set it permanently in your configuration file, or turn on at runtime with %autocall 1.

      You can force auto-parentheses by using '/' as the first character of a line. For example::

      In [1]: /globals # becomes 'globals()'

关于ipython - 如果我在 iPython 中输入/,为什么会得到空元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28541102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com