0% found this document useful (0 votes)
36 views5 pages

Sqlite

Sqlite Basic Concets

Uploaded by

azlaank1284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views5 pages

Sqlite

Sqlite Basic Concets

Uploaded by

azlaank1284
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1. What is Python Path? How to set Python Path.

● Python Path is an environment variable that tells the operating system where to find
Python executables and libraries.
● To set Python Path:
○ Windows:
1. Right-click on "This PC" > "Properties."
2. Click "Advanced system settings."
3. Go to "Environment Variables."
4. Under "System variables," find "Path" and edit it.
5. Add the path to your Python installation (e.g., C:\Python39).

macOS/Linux: Open terminal and type:


bash
Copy code
export PATH="/usr/local/bin/python3:$PATH"

○ You can add this line to your .bashrc or .zshrc file for permanent changes.

2. What is to use cursor when cursor in with example. we need python explain

● In Python, the cursor is used in databases to interact with data. It allows you to
execute SQL queries and fetch data.

Example using SQLite:


python
Copy code
import sqlite3

# Connect to a database
conn = sqlite3.connect('example.db')
cursor = conn.cursor()

# Create a table
cursor.execute('''CREATE TABLE students (name TEXT, age INTEGER)''')

# Insert data
cursor.execute("INSERT INTO students VALUES ('John', 21)")

# Fetch data
cursor.execute("SELECT * FROM students")
result = cursor.fetchall()

print(result) # Output: [('John', 21)]


conn.commit()
conn.close()

3. What is namespace and scope? Explain the types of in detail.

● Namespace: A namespace is a system that helps in organizing and managing the


names of variables, functions, etc., to avoid naming conflicts.
○ Types of namespaces:
■ Built-in namespace: Contains names of Python's built-in functions
(e.g., print, len).
■ Global namespace: Names defined at the top level of a module or
script.
■ Local namespace: Names inside a function or method.
■ Enclosed/Nonlocal namespace: Names in outer functions when
working with nested functions.
● Scope: The region in a program where a variable is accessible.
○ Types of scope:
■ Local scope: Inside a function.
■ Global scope: Outside any function, accessible throughout the
module.
■ Enclosed/Nonlocal scope: Variables in nested functions.
■ Built-in scope: Includes built-in functions and exceptions.

4. How to set Python Path, explain Concept of and Packages. namespace, scope

● Setting Python Path: Explained in Answer 1.


● Packages: A package is a collection of Python modules organized in directories. It
can have sub-packages and modules. To create a package:
1. Create a directory.
2. Add __init__.py file (can be empty).
3. Add your module files.

Example directory structure:


markdown
Copy code
mypackage/
__init__.py
module1.py
module2.py

5. What is matplotlib.pyplot? Explain the types of chart Data 10 visualization. we use


for
● matplotlib.pyplot is a Python library used for creating static, interactive, and
animated visualizations. It's a part of the matplotlib library and is typically used to
plot graphs.
● Types of charts in data visualization:
1. Line chart: Shows trends over time.
2. Bar chart: Compares data between different groups.
3. Histogram: Shows the distribution of numerical data.
4. Scatter plot: Displays relationships between two numerical variables.
5. Pie chart: Shows the proportions of categories.
6. Box plot: Summarizes the distribution of a dataset.
7. Heatmap: Represents data in matrix form.
8. Area chart: Similar to line charts but filled below the line.
9. Bubble chart: A scatter plot with additional size dimension for the points.
10. Violin plot: Combines a box plot with a kernel density plot.

Example of creating a bar chart with matplotlib.pyplot:


python
Copy code
import matplotlib.pyplot as plt

categories = ['A', 'B', 'C']


values = [10, 20, 15]

plt.bar(categories, values)
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Chart Example')

● plt.show()

Here are the answers to your additional questions:

**7. What is matplotlib.pyplot? What function of pyplot we use for plotting in Data
Visualization?**

- **matplotlib.pyplot** is a module in the **matplotlib** library that provides a MATLAB-like


interface for creating plots and charts. It allows you to create visualizations like line charts,
bar charts, scatter plots, etc., using simple functions.

- Common **pyplot functions** used for plotting in data visualization:


- `plt.plot()` - Plots a line graph.
- `plt.bar()` - Creates a bar chart.
- `plt.scatter()` - Creates a scatter plot.
- `plt.hist()` - Creates a histogram.
- `plt.pie()` - Creates a pie chart.
- `plt.xlabel()` / `plt.ylabel()` - Adds labels to the x and y axes.
- `plt.title()` - Adds a title to the plot.
- `plt.legend()` - Adds a legend to the plot.
- `plt.show()` - Displays the plot.

**8. Explain Select, Insert, Update, Delete Using with Execute function to interact with
SQLite.**

In **SQLite**, you interact with the database using **cursor.execute()** to run SQL queries.
Here's how to use it for `SELECT`, `INSERT`, `UPDATE`, and `DELETE`:

- **SELECT**: Fetch data from the database.


```python
cursor.execute("SELECT * FROM students WHERE age > 20")
results = cursor.fetchall()
for row in results:
print(row)
```

- **INSERT**: Insert new records into the table.


```python
cursor.execute("INSERT INTO students (name, age) VALUES ('Alice', 22)")
conn.commit() # Save changes to the database
```

- **UPDATE**: Modify existing records.


```python
cursor.execute("UPDATE students SET age = 23 WHERE name = 'Alice'")
conn.commit()
```

- **DELETE**: Remove records from the table.


```python
cursor.execute("DELETE FROM students WHERE name = 'Alice'")
conn.commit()
```

**1. What is matplotlib? What is the difference between bar, scatter, line, and histogram?**

- **matplotlib** is a comprehensive library used in Python for creating static, animated, and
interactive visualizations. It is widely used for plotting different types of graphs to visualize
data.

- **Differences between various plot types**:


- **Bar chart**: Used to compare discrete categories or groups. Each bar represents a
category, and its height shows the value.
- Example: Comparing the population of different cities.
- Function: `plt.bar()`
- **Scatter plot**: Shows the relationship between two numerical variables. Each point
represents one observation.
- Example: Plotting height vs weight of individuals.
- Function: `plt.scatter()`

- **Line chart**: Used to show trends over time or continuous data. Each point is connected
by a line.
- Example: Tracking the stock price of a company over time.
- Function: `plt.plot()`

- **Histogram**: Displays the distribution of a dataset by grouping data into bins and
showing the frequency of each bin.
- Example: Showing the distribution of exam scores in a class.
- Function: `plt.hist()`

These chart types serve different purposes depending on the type of data and the message
you want to convey.

You might also like