hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    Which datatype is mostly returned by fetchall() method in Python-MySQL connectivity? Select the most common answer.
    Question

    Which datatype is mostly returned by fetchall() method in Python-MySQL connectivity?
    Select the most common answer.

    A.

    A single list or an empty list, if no more rows are available.

    B.

    A list of tuples or an empty list, if no more rows are available.

    C.

    A list of dictionaries or an empty list, if no more rows are available.

    D.

    A single tuple or an empty tuple, if no more rows are available.

    Correct option is B


    In Python's MySQL connectivity, the fetchall() method returns a list of tuples by default. Each tuple represents a row from the result set. If there are no more rows to retrieve, it returns an empty list. This behavior is common when you want to fetch all the rows from a query result at once.
    Important Key Points:
    1. The fetchall() method is used to fetch all rows from the result of a query in MySQL.
    2. It returns a list of tuples, where each tuple represents a row in the result set.
    3. If no rows are available, it returns an empty list.
    4. This method is commonly used in conjunction with the cursor to retrieve the full result set from the database at once.
    5. If there is no data in the result set, an empty list helps in avoiding errors when processing the result.
    Knowledge Booster:
    · Option (a): This is incorrect because fetchall() does not return a single list. It returns a list of tuples, where each tuple corresponds to a row in the result set.
    · Option (c): This is also incorrect. The fetchall() method does not return a list of dictionaries. It returns a list of tuples, not dictionaries.
    · Option (d): This option is wrong because fetchall() does not return a single tuple. It returns a list of tuples, each tuple representing one row in the result set.

    Free Tests

    Free
    Must Attempt

    DSSSB PRT Full Mock - 01

    languageIcon English
    • pdpQsnIcon200 Questions
    • pdpsheetsIcon200 Marks
    • timerIcon120 Mins
    languageIcon English
    Free
    Must Attempt

    Educational Psychology & Pedagogy - 01

    languageIcon English
    • pdpQsnIcon20 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon15 Mins
    languageIcon English
    Free
    Must Attempt

    DSSSB PRT PYP Held on 7th March 2022 Shift 1

    languageIcon English
    • pdpQsnIcon200 Questions
    • pdpsheetsIcon200 Marks
    • timerIcon120 Mins
    languageIcon English
    test-prime-package

    Access ‘EMRS PGT’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    368k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow