标识符4中的字符无效

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了标识符4中的字符无效相关的知识,希望对你有一定的参考价值。

我的代码继续说它有无效的字符标识符。

import random
answer1 = ("Absolutely!")
answer2 = ("No way Pedro!")
answer3 = ("Go for it tiger.")
input("Welcome to the Magic 8 Ball game and use it to answer your questions...")
question = int(input("Ask me for any advice and I’ll help you out.  Type in your question and then press Enter for an answer."))
print("shaking.... 
" * 4)
choice = random.randint(1,3)

if choice == 1:
  answer = Answer1
elif choice == 2:
  answer = Answer2
else:
  answer = Answer3
print(answer)
答案

标识符中的无效字符表示您有不应该存在的内容。如果您的错误消息如下所示:

  File "invalchar.py", line 23
    values =  list(analysis.values ())
            ^
SyntaxError: invalid character in identifier

然后它会告诉你“无效字符”的确切位置。我建议查看整个代码以查找任何语法错误。此外,我会开始使用良好的格式,如下所示:

import random

answer1=("Absolutely!")
answer2=("No way Pedro!")
answer3=("Go for it tiger.")

input("Welcome to the Magic 8 Ball game and use it to answer your 
questions...")

question = int(input("Ask me for any advice and I’ll help you out.  
Type in your question and then press Enter for an answer."))

print("shaking.... 
" * 4)
choice=random.randint(1,3)

if choice == 1:
    answer = Answer1

elif choice == 2:
    answer = Answer2

else:
    answer = Answer3
    print(answer)

这使得阅读更容易。此外,无效字符可能是空格,因此请确保您的间距正确。

以上是关于标识符4中的字符无效的主要内容,如果未能解决你的问题,请参考以下文章

swift 4 中的应用内购买无效的产品标识符

Newtonsoft.Json.JsonReaderException:无效的 JavaScript 属性标识符字符:,

GLSL:“未声明的标识符‘texture2D’的无效调用”

变量小结

python调用oracle函数ORA-00904无效标识符

PL-SQL:ORA-00904 - 标识符无效 - Select and Pivot 子句中的列