在下面的代码中,我有一个变量"split_data[i]",我将这个变量的每个元素与"文本变量"中的一个文件进行比较:
i = 0
while i < len(split_data):
print(split_data[i])
if split_data[i] in text: #string in present in the text file
print("Matched" )
else:
print("not matched" )
i += 1
split_data[4] 的值是 '03:31',它存在于文本中,但输出仍然"不匹配"而如果我的代码是这样的:
i = 0
while i < len(split_data):
print(split_data[i])
if '03:31' in text: #string in present in the text file
print("Matched" )
else:
print("not matched" )
i += 1
输出匹配。或者我们可以说:
if '03:31' in split_data[4]:
print("true")
else:
print('false')
是真的,但
if '03:31' == split_data[4]:
print("true")
else:
print('false')
是假的
这是我的整个代码:
import mysql.connector
import numpy as np
conn=mysql.connector.connect(user="root", password="",
host="localhost", database="videojs")
# prepare a cursor object using cursor() method
def read_from_db():
cursor = conn.cursor()
cursor.execute("select time_arr from info where id ='53'")
data=cursor.fetchone()
print(data)
the_new_list = [x.split(',') for x in data]
print(the_new_list)
str_data = ''.join(map(str, the_new_list))
print(len(str_data))
split_data=str_data.strip('[]').split(',')
print(split_data)
print(len(split_data))
i = 0
while i
please guide me how to resolve this i am a beginner
this is the data in text:
1 00:00 --> 00:06 welcome to your very<font color="#CCCCCC"> first tutorial</font><font color="#E5E5E5"> on</font> 2 00:02 --> 00:08 beginning HTML HTML<font color="#E5E5E5"> is the bedrock</font><font color="#CCCCCC"> of</font> 3 00:06 --> 00:10 <font color="#CCCCCC">the world wide web</font><font color="#E5E5E5"> and if you're going</font> 4 00:08 --> 03:31 <font color="#CCCCCC">to do anything</font><font color="#E5E5E5"> even</font><font color="#CCCCCC"> in</font><font color="#E5E5E5"> other languages</font>
也许您可能想重新访问您的循环结构。
考虑以下代码段:
text = "one two three four five"
split_data = ["one", "two", "three", "four", "five"]
for i in split_data:
print( "matched" if i in text else "not matched" )