【发布时间】:2019-01-31 13:37:25
【问题描述】:
>>> 1, == (1,)
File "<ipython-input-34-bddb0dd08d2c>", line 1
1, == (1,)
^
SyntaxError: invalid syntax
为什么我会收到SyntaxError?控制台中的行指向比较运算符'=='。我试图比较 2 个元组。是的,(1,) == (1,) 有效。
这和这个……有关系吗?
1,
Out[1]: (1,)
,1
Traceback (most recent call last):
File "<ipython-input-2-d73977cd7b2e>", line 1, in <module>
1("")
TypeError: 'int' object is not callable
def h():
print("hello from h")
h
Out[4]: <function __main__.h>
h()
hello from h
,h
Traceback (most recent call last):
File "<ipython-input-6-89db5d24b531>", line 1, in <module>
h("")
TypeError: h() takes 0 positional arguments but 1 was given
def h(""):
print("hello from h")
File "<ipython-input-7-e4606aaf3740>", line 1
def h(""):
^
SyntaxError: invalid syntax
def h(a):
print("hello from h")
,h
hello from h
我觉得这很有趣 - Python 3.6.3,不会发生在 2.7 或 3.5...
,ord A
Out[112]: 65
这有点难看。刚刚尝试了新的 IDE - Pycharm with python 3.6.3。控制台在 ",ord A" 上给了我语法错误,但 Spyder 3.3.1 没有。这与IPython有关吗? 7.2 在 ",ord A" >> 65 上给出相同的结果。
好的,2019 年 2 月 5 日。我好像掉进了黑洞。一个 IPython 黑洞。似乎我对控制台使用的另一种子语言 IPython 感到困惑。 IPython 中的 %Autocall '使函数无需键入括号即可调用'。尽管将 %Autocall 设置为 0 似乎仍会启用此行为。
【问题讨论】:
-
int1 后面有一个逗号,这是无效的 python -
格式化导致 ^ 看似指向第一个等号,但控制台显示最后一个等号。
-
@aws_apprentice 我认为这不是 OP 的意图,而问题是为什么在这种情况下不能使用
a = 1,2中的语法。 -
这有帮助吗?
1, 1 == 1>>>(1, True) -
对我来说很有意义。
1, 1 == 1等价于1, (1 == 1)。