我试图调用我为Python中的'if'语句创建的变量。 这是一个总结版本:
public class Sorter : IComparer
{
public int Compare(object x, object y)
{
var tx = x as TreeNode;
var ty = y as TreeNode;
// If this is a child node, preserve the same order by comparing the node Index, not the text
if (tx.Parent != null && ty.Parent != null)
return tx.Index - ty.Index;
// This is a root node, compare by name.
return string.Compare(tx.Text, ty.Text);
}
}
但是我收到了错误:
yes = ("yes", "y")
question1 = input("Am I right?")
if question1.lower() in yes:
print ("you are correct")
我的实际代码很奇怪,但是你去((这不是为了佯装)):
--'in <string>' requires string as left operand, not builtin_function_or_method
答案 0 :(得分:-1)
在python 2.x中;
您必须使用raw_input
代替input
input()
实际上将输入评估为Python代码。
raw_input()
返回用户输入的逐字字符串。
yes = ("yes", "y")
question1 = raw_input("Am I right?")
if question1.lower() in yes:
print("you are correct")
刚刚在https://www.codechef.com/ide上尝试了您的代码,完全没问题。