简体   繁体   English

Jupyter笔记本中python 3中的标识符中的无效字符,箭头指向负号。 我的清单中可以没有否定词吗?

[英]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.

相关问题 查找列表是否有负号 - to find if list have the negative sign python 列表中的负号交换 - Negative sign swapping in a python list 我想用“%”号显示我的EXCEL数据。 我如何使用python做到这一点 - I want to display my EXCEL data with “%” sign. How can i do so by using python Python / pandas function 替换负号中的“-”而不是负号(“-1”中的“-”) - Python / pandas function to replace '-' negative sign but not negative sign in negative numbers ( '-' in '-1') 如何删除列表中的负号? - How to remove the negative sign in a list? 如何检查列表中的整数或浮点数是正号还是负号? - How can I check if an integer or float number in a list is positive or negative in sign? 我不小心删除了我的 Jupyter Notebook - I have accidentally deleted my Jupyter Notebook Python子集操作中的负号 - Negative sign in Python Subseting operations 我如何得到这个答案的否定? 为什么我退回function时不能只加一个负号? - How do I get the negative of this answer? Why can I not just put a negative sign when returning the function? 我可以打开 jupyter 笔记本,但无法在 Mac 上运行带有 python 脚本的笔记本 - I can open a jupyter notebook, but I cannot run the notebook with python script in it on my Mac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM