[python]Python function passing more than one value

Reference: https://stackoverflow.com/questions/354883/how-do-you-return-multiple-values-in-python

I just realize the python function can pass multiple values through dictionary!

Here’s the code which I tried:

import sqlite3

def connect_db():
    conn = sqlite3.connect("lite.db")
    cur = conn.cursor()
    return {'conn': conn, 'cursor': cur}

def create_table(conn):
    conn['cursor'].execute("CREATE TABLE IF NOT EXISTS store (item TEXT, quantity INTEGER, price REAL)")

def insert(conn, item, quantity, price):
    conn['cursor'].execute("INSERT INTO store VALUES(?,?,?)", (item, quantity, price))

def view(conn):
    conn['cursor'].execute("SELECT * FROM store")
    rows = conn['cursor'].fetchall()
    return rows

if __name__ == '__main__':

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s