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

PYTHON

Uploaded by

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

PYTHON

Uploaded by

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

Date: 03-10-23

Python

1) What is the module in Python, and why is it used?


Ans: In Python, a module is a file containing Python code, facilitating code organization,
reusability, and namespace management. Modules enable the creation of separate files for
functions, classes, and variables, making code more manageable and promoting reuse across
different programs. Modules enhance code readability by grouping related functionality
together, aiding both developers and maintainers. Modules are created by saving code in .py
files with matching names, which can then be imported into other scripts. Overall, modules are a
fundamental concept in Python's modular programming approach, essential for structuring and
maintaining code in a clear and efficient manner.

2) What is a decorator in Python?


Ans: In Python, a decorator is a special type of function that can be used to modify or enhance
the behavior of other functions or methods without changing their source code. Decorators are
often used to add functionality to functions or methods, such as logging, authentication, or
performance monitoring, in a clean and reusable way.

Decorators are typically applied using the "@" symbol followed by the decorator function's name
above the function definition. When the decorated function is called, the decorator function is
executed before the decorated function's code.

3) Explain the concept of list comprehension in Python.


Ans: List comprehension in Python is a concise way to create lists by applying an expression to
each item in an iterable (e.g., a list, tuple, or range) and optionally filtering items based on a
condition.
Ex: # List comprehension with condition
numbers = [1, 2, 3, 4, 5]
even_numbers = [num for num in numbers if num % 2 == 0]

# Result: [2, 4]
In this example, the list comprehension filters out only the even numbers from the numbers list
using the condition if num % 2 == 0.

4) What is the generator in Python, and how does it differ from a regular function?
Ans: In Python, a generator is a type of iterable that generates values on-the-fly, conserving
memory by producing items one at a time rather than storing them all at once. It's created using
a function with the yield keyword instead of return. When the generator function is called, it
returns a generator object. Iterating over this generator using a loop or other iterable methods
yields values one at a time, computing them when requested. Unlike regular functions that
compute and return a result, generators maintain their state between calls, allowing for efficient
processing of large or infinite sequences, making them particularly useful for memory-intensive
tasks like working with large datasets or streaming data.

5) How do you work with JSON data in Python?


Ans: To work with JSON data in Python:

Import the json module.


To serialize Python data to JSON, use json.dumps() to convert a Python object to a JSON string.
To deserialize JSON to Python, use json.loads() to parse a JSON string into a Python object.
For JSON files, use json.load() to read JSON from a file and json.dump() to write Python data to a
JSON file.

SQL

1) Explain the difference between SQL and NoSQL databases.


Ans: SQL (Structured Query Language) and NoSQL (Not Only SQL) databases are two
fundamentally different types of database management systems.

SQL databases are relational databases that use tables to store structured data with a fixed
schema. They use structured query language for data manipulation and support ACID
(Atomicity, Consistency, Isolation, Durability) transactions. SQL databases are suitable for
complex queries and relationships but may lack scalability.

NoSQL databases, on the other hand, are non-relational databases that store unstructured
or semi-structured data with a flexible schema. They offer high scalability and can handle
large volumes of data but may sacrifice ACID compliance for better performance. NoSQL
databases are ideal for dynamic, rapidly changing data and horizontal scaling. The choice
between SQL and NoSQL depends on the specific requirements of a project.

2) What are the basic SQL commands for interacting with a database?
Ans: Basic SQL commands for interacting with a database include:

SELECT: Retrieves data from one or more tables.


Ex: SELECT column1, column2 FROM table_name WHERE condition;

INSERT: Adds new rows of data into a table.


Ex: INSERT: Adds new rows of data into a table.

UPDATE: Modifies existing data in a table.


Ex: UPDATE table_name SET column1 = new_value WHERE condition;

DELETE: Removes rows from a table.


EX: DELETE FROM table_name WHERE condition;
CREATE TABLE: Creates a new table with specified columns and data types.
Ex: CREATE TABLE table_name (
column1 datatype,
column2 datatype
);

3) How do you retrieve all records from a table named Customers?


Ans:
To retrieve all records from a table named "Customers" in SQL, you can use the SELECT
statement without a WHERE clause.
Ex: SELECT * FROM Customers;

4) What is a primary key in a database and why is it important?


Ans: A primary key in a database is a special column or set of columns that uniquely
identifies each row (record) in a table. Its main characteristics are:

Uniqueness: Every value in the primary key column(s) must be unique across all rows in the
table.

Non-null: The primary key column(s) cannot contain NULL values, ensuring that each row
has a valid and unique identifier.

The primary key is important for several reasons:

Uniqueness: It enforces data integrity by preventing duplicate rows, ensuring data accuracy.

Efficient Retrieval: The primary key is used to quickly locate specific rows, improving query
performance.

Relationships: Primary keys are used to establish relationships between tables through
foreign keys, enabling data normalization and referential integrity.

Indexing: Databases automatically create indexes on primary key columns, speeding up data
retrieval.

Data Integrity: Primary keys help maintain data consistency and prevent data anomalies.

5) What is a foreign key in a database and how is it used?


Ans: A foreign key in a database is a field or set of fields in one table that refers to the
primary key of another table. It establishes a relationship between the two tables and
enforces referential integrity, ensuring that the data in the tables remains consistent and
that relationships between records are valid.
Foreign keys establish connections between tables, often representing parent-child
relationships, like linking "Customers" to "Orders" in an online store database. They ensure
referential integrity by guaranteeing values in the child table's foreign key match the parent
table's primary key, preventing data inconsistencies. This maintains data accuracy and
simplifies data retrieval using SQL JOINs. Additionally, some databases allow cascade actions
for foreign keys, automating actions like deleting related child records when a parent record
is deleted, enhancing data management and integrity.

Tableau
1) Explain the concept of hierarchies in Tableau.
Ans: In Tableau, hierarchies are organizational structures for data dimensions, facilitating
interactive exploration and visualization. They define levels of detail within categorical
data, like time or geography, enabling users to drill down into finer details or roll up to
broader summaries with ease. Hierarchies simplify data aggregation, enhance
visualizations, and act as filters for focused analysis. Users can dynamically navigate
through data levels, fostering a more intuitive dashboard experience. By providing
flexibility in data exploration and visualization, hierarchies empower Tableau users to
gain deeper insights and effectively communicate findings in a structured, user-friendly
manner.

2) What is the Tableau story and how can it be used to present data?
Ans: A Tableau story is a feature that allows you to combine sheets, dashboards, and text
descriptions into a sequence to create a data-driven narrative. Stories help present data
effectively by guiding the audience through key insights, analysis, and findings. They
enable storytellers to arrange visualizations and add context, annotations, and
explanations, creating a cohesive and interactive data presentation. Stories are
particularly useful for conveying a clear and compelling data-driven narrative, making
complex information more understandable and engaging for stakeholders, clients, or
decision-makers. Users can interact with story points, filter data, and explore
visualizations, enhancing their understanding of the presented data.

3) How do you create a calculated field to perform a specific aggregation or transformation


in Tableau?
Ans: To create a calculated field for a specific aggregation or transformation in Tableau,
follow these steps:

 Right-click the data pane, then choose "Create Calculated Field."


 In the calculation editor, write your formula using Tableau's calculation
language. For example, to calculate the average of a numerical field called
"Sales," use: AVG([Sales]).
 Give the calculated field a name and click "OK" to create it.
 Drag and drop the new calculated field into your visualization to use it like any
other field.
 Customize its aggregation settings (e.g., sum, average) or apply additional
calculations (e.g., IF statements) as needed.
Calculated fields are dynamic and update when data changes, enabling you to perform
custom aggregations or transformations to suit your analysis and reporting needs.

4) How can you create a parameterized calculated field in Tableau?


Ans:
To create a parameterized calculated field in Tableau:

Right-click in the "Data Pane" and select "Create Parameter."


Define the parameter details (name, data type, allowable values, etc.).
In a calculated field, reference the created parameter to incorporate its value into
calculations.
Use the parameterized calculated field in your visualizations.
Users can interactively change the parameter's value, dynamically affecting the
calculated field's results in the visualization.
This allows for flexible, interactive analysis by letting users adjust parameters to see
different outcomes in the data visualizations.

5) Explain the use of sets in Tableau.


Ans: Sets in Tableau are custom subsets of data created based on specific conditions or
criteria. They help in data exploration, analysis, and visualization by categorizing or
isolating data points that meet defined conditions. Tableau offers two types of sets:
Fixed Sets (static criteria) and Dynamic Sets (criteria based on user interactions). Sets can
be used for various purposes, including highlighting data points, comparing subsets,
filtering data, and creating complex calculated fields. They enhance the depth of analysis
and enable users to focus on specific aspects of the data, facilitating clearer insights and
more targeted visualizations in Tableau dashboards.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy