【问题标题】:python string comparison failed [closed]python字符串比较失败[关闭]
【发布时间】:2020-11-19 04:04:59
【问题描述】:

在python中,我写了一个程序来比较两个字符串。 代码如下

d = data.iloc[0]

cmpdate = d['quant_date']

print(cmpdate)

if (cmpdate=='2010-03-18'):

    print("=================", dt)

else:

    print("xxxxxxxxxxxxx", cmpdate)

结果是

2010-03-18

xxxxxxxxxxxxx 2010-03-18

两个字符串完全相同。 问题是什么? TIA

【问题讨论】:

  • print(type(cmpdate), repr(cmpdate))

标签: python string compare match


【解决方案1】:

确保将两个日期都转换为日期时间格式
并检查结果
使用to_datetime()函数
这很好用

【讨论】:

    猜你喜欢
    • 2021-02-10
    • 1970-01-01
    • 2016-07-05
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多