[英]What should I use for this?
OK. 好。 I'm back on track for my quest to make a server-sided laughing man head for my Toontown private server.
我正朝着让我的Toontown私人服务器的服务器端大笑的人走上正轨。 Now, I've made an if statement to filter who IS ME and who ISN'T ME.
现在,我做了一个if语句来过滤谁是我和谁不是我。
if invoker.getName() = "Toonman"
But, It said invalid syntax. 但是,它说语法无效。 I came here to ask, what is the proper syntax for this line of python code?
我来这里问,这行python代码的正确语法是什么? Thank you for your help.
谢谢您的帮助。
=
is an assignment =
是一项作业
==
is an equality check. ==
是相等检查。
is
is an identity check (thanks!) is
身份检查(谢谢!)
if invoker.getName() == "Toonman":
if invoker.getName() = "Toonman"
In the code above, if invoker.getName()
is correct, as is "Toonman"
. 在上面的代码中,
if invoker.getName()
是正确的,那么"Toonman"
也是"Toonman"
。 The error comes because in a statement like this, if
requires a ==
operator. 出现错误是因为在这样的语句中,
if
需要==
运算符。
From http://www.tutorialspoint.com/python/python_basic_operators.htm : 从http://www.tutorialspoint.com/python/python_basic_operators.htm :
=
"Assigns values from right side operands to left side operand" =
“将值从右侧操作数分配到左侧操作数”
==
If the values of two operands are equal, then the condition becomes true. ==
如果两个操作数的值相等,则条件变为true。
Basically you use =
when you are setting something like name = "Toonman"
, and use ==
when you are checking something like if name == "Toonman":
. 基本上你使用
=
当你设置类似name = "Toonman"
,并使用==
当你正在检查类似if name == "Toonman":
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.