Skip to main content
 首页 » 编程设计

python之比较python中的两个字符串

2024年11月01日24sky-heaven

在 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”的内容以检查其中的内容。确保大小写相同(小写/大写字母)。