Python 中的构建函数中是否有任何可以实现两个比较两个字符串的函数。
我尝试使用 ==
运算符比较两个字符串,但不起作用。
try:
if company=="GfSE-Zertifizierungen":
y=2
if x<y:
print "**************Same company***********"
x=x+1
flag=0
pass
if x==y:
flag=1
x=0
count=count+1
except Exception as e:
print e
这甚至没有显示任何错误,也没有解决。 谁能帮我解决我出错的地方
最佳答案
在Python中要比较字符串,您应该使用==
运算符。
例如:
a = "hello"
b = "hello2"
c = "hello"
然后
a == b # should return False
a == c # should return True
建议:打印变量“company”的内容以检查其中的内容。确保大小写相同(小写/大写字母)。
关于python - 在Python中比较两个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22937269/