Pass data to a varaible with pyodbc

Question:

I connected to a database and there are some datas in it.

In here I print the name of the person whose id is 2

cursor.execute('Select Name from Customers Where Id = 2')
for row in cursor:
    print(row)

The name of the person is "Alex" it this code is being printed like this

('Alex', )

I want to pass this name "Alex" to a varaible and then when i print it I want it to be look like

print(name)

answer

Alex

How can I do it?

Asked By: AlexDeSouza

||

Answers:

print(row[0])

It is a tuple, so extract so first element from it.

Answered By: Itération 122442
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.