Advertisements
Advertisements
Question
Which method is used to connect a database? Give an example.
Short/Brief Note
Advertisements
Solution
- Connect()method is used to connect a database
- Connecting to a database means passing the name of the database to be accessed.
- If the database already exists the connection will open the same. Otherwise, Python will open a new database file with the specified name.
Example:
import sqlite3
# connecting to the database
connection = sqlite3.connect (“Academy.db”)
# cursor
cursor = connection. cursor()
shaalaa.com
Is there an error in this question or solution?
