python - 在Python中比较两个字符串

标签 python string

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/

相关文章:

python - 如何使用 scikit 学习多类案例绘制 ROC 曲线?

python - 大字符串的某些部分不会被 str.replace() 函数替换

javascript - 循环遍历字符串

string - Go 中如何检查字符串是全大写还是小写?

c++ - 在子字符串后插入字符串

python - 变分自动编码器损失函数(keras)

python - Python 是否缓存导入的文件?

PyCharm 上的 Python 崩溃并显示 'Process finished with exit code -1073740940 (0xC0000374)'

python - PYQT5如何更改QSqlTableModel的mysql odbc连接中的方案?

string - 在Rust中返回格式化的字符串