I have a python function rows
which output as:
(
[u'ABC'],
[u'DEF'],
[u'GHI']
)
I want to search DEF
in this and print("Hello")
I did this:
for i in rows[]:
if i == "DEF":
print("Hello")
But this is not working. Can someone please guide
rows = ( [u'ABC'], [u'DEF'], [u'GHI'])
print rows
for i in rows:
print i
if i == [u"DEF"]:
print("Hello")
if i[0] == u"DEF":
print "world"
I do not know, what exactly is your problem. The string is inside a list. Either you compare the complete list with a list of this string or the first element of the list with the string itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.