V
V
Vitaliy4452021-09-14 20:00:36
Python
Vitaliy445, 2021-09-14 20:00:36

What is wrong with this check in the loop?

Here is the code

def get_all_users_First(chat_id_user):
    db.cursor.execute("SELECT chat_user_id FROM users")
    rows = db.cursor.fetchall()
    print(rows)
    for row in rows:
        print(chat_id_user)
        print(row)
        print(rows)
        if chat_id_user == row:
            print('True')
            return True
        else:
            print('false')
            return False

6140d4d49eb1a669828625.png

What's wrong? It seems that the first elements are the same, but if still returns False

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2021-09-14
@Vitaliy445

if chat_id_user == row[0]:

It looks like the first elements are the same
And not identical, and not elements.
1641862320 and ('1641862320',) - what do they have in common? Nothing.
1641862320 - string, ('1641862320') - tuple.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question