From 615bc8c2e7c53a5d528cf7d98360937dbcc808b3 Mon Sep 17 00:00:00 2001 From: CSnap Date: Sun, 19 Nov 2023 08:04:22 +0000 Subject: [PATCH] Modified Python Sheet. --- python.md | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/python.md b/python.md index 674aa6a..071bb5e 100644 --- a/python.md +++ b/python.md @@ -16,26 +16,16 @@ 12. [Exception Handling](#exception-handling) 13. [Classes and Objects](#classes-and-objects) 14. [SQLite3 Database Connection](#sqlite3-database-connection) - - 14.1 [Connecting to a Database](##connecting-to-a-database) - - 14.2 [Creating a Table](#creating-a-table) - - 14.3 [Inserting Data](#inserting-data) - - 14.4 [Querying Data](#querying-data) - - 14.5 [Updating Data](#updating-data) - - 14.6 [Deleting Data](#deleting-data) - - 14.7 [Closing the Connection](#closing-the-connection) - + 14.1 [Connecting to a Database](#connecting-to-a-database) + 14.2 [Creating a Table](#creating-a-table) + 14.3 [Inserting Data](#inserting-data) + 14.4 [Querying Data](#querying-data) + 14.5 [Updating Data](#updating-data) + 14.6 [Deleting Data](#deleting-data) + 14.7 [Closing the Connection](#closing-the-connection) 15. [JSON Data Connection](#json-data-connection) - - 15.1 [Loading JSON Data](#loading-json-data) - - 15.2 [Writing JSON Data](#writing-json-data) + 15.1 [Loading JSON Data](#loading-json-data) + 15.2 [Writing JSON Data](#writing-json-data) ## Variables @@ -243,9 +233,9 @@ import sqlite3 import json ``` -## 14. SQLite3 Database Connection +## SQLite3 Database Connection -### 14.1 Connecting to a Database +### Connecting to a Database ```python # Connect to a database (creates a new database if it doesn't exist) @@ -255,7 +245,7 @@ conn = sqlite3.connect('example.db') cursor = conn.cursor() ``` -### 14.2 Creating a Table +### Creating a Table ```python # Create a table @@ -271,7 +261,7 @@ cursor.execute(''' conn.commit() ``` -### 14.3 Inserting Data +### Inserting Data ```python # Insert data into the table @@ -284,7 +274,7 @@ cursor.execute(''' conn.commit() ``` -### 14.4 Querying Data +### Querying Data ```python # Fetch all rows from the table @@ -296,7 +286,7 @@ for row in rows: print(row) ``` -### 14.5 Updating Data +### Updating Data ```python # Update data in the table @@ -310,7 +300,7 @@ cursor.execute(''' conn.commit() ``` -### 14.6 Deleting Data +### Deleting Data ```python # Delete data from the table @@ -323,7 +313,7 @@ cursor.execute(''' conn.commit() ``` -### 14.7 Closing the Connection +### Closing the Connection ```python # Close the cursor and connection when done @@ -331,9 +321,9 @@ cursor.close() conn.close() ``` -## 15. JSON Data Connection +## JSON Data Connection -### 15.1 Loading JSON Data +### Loading JSON Data ```python # Load JSON data from a file @@ -342,7 +332,7 @@ with open('data.json', 'r') as json_file: print(data) ``` -### 15.2 Writing JSON Data +### Writing JSON Data ```python # Write Python data to a JSON file