[英]invalid character in identifier in python 3 in a Jupyter notebook, arrow pointing to a negative sign. Can I not have a negative in my list?
I am trying to find the mean of a list. 我正在尝试查找列表的含义。 I believe the negative number in the beginning of my list is somehow throwing me for a loop.
我相信清单开头的负数会以某种方式使我陷入困境。 Please show me the proper way to find the mean of this simple list.
请向我展示找到此简单列表的均值的正确方法。
B = [−5,3,12,190,−10]
print(np.mean(B))
#OUTPUT:
File "<ipython-input-35-5b44dec66063>", line 1
B = [−5,3,12,190,−10]
^
SyntaxError: invalid character in identifier
I'm assuming you maybe copy/pasted your code from somewhere. 我假设您可能从某处复制/粘贴了代码。 That is not a valid negative sign in Python.
在Python中,这不是有效的负号。 Use the key next to the 0 on your keyboard.
使用键盘上0旁边的键。
You can check to see if you are using the correct value. 您可以检查是否使用了正确的值。
Enter in this for the proper hyphen: 在此输入正确的连字符:
a = ord('-')
And this for yours: 而这对于你的:
b = ord('−')
and output them to see the difference. 并输出它们以查看差异。
I copied and pasted part of your code into python: 我将部分代码复制并粘贴到python中:
c = '−5'
print(ord(c[0]))
print(ord('-'))
Gives: 得到:
8722
45
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.