0% found this document useful (0 votes)
17 views8 pages

7 Days Analytics Course 3feiz7 2

The CASE statement in SQL is used to create different outputs based on different conditions. The COALESCE function in SQL is used to return the first non-NULL value in a list. The NULLIF function in SQL is used to compare two expressions and returns NULL if they are equal, otherwise the first expression. To handle duplicate records, the DISTINCT keyword or GROUP BY clause can be used.

Uploaded by

anupamakarupiah
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)
17 views8 pages

7 Days Analytics Course 3feiz7 2

The CASE statement in SQL is used to create different outputs based on different conditions. The COALESCE function in SQL is used to return the first non-NULL value in a list. The NULLIF function in SQL is used to compare two expressions and returns NULL if they are equal, otherwise the first expression. To handle duplicate records, the DISTINCT keyword or GROUP BY clause can be used.

Uploaded by

anupamakarupiah
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/ 8

9

What is the purpose of the CASE statement in SQL?

The CASE statement in SQL is used to create different outputs based on different conditions.

What is the purpose of the COALESCE function in SQL?

The COALESCE function in SQL is used to return the first non-NULL value in a list.

What is the purpose of the NULLIF function in SQL?

The NULLIF function in SQL is used to compare two expressions. If the expressions are equal,
the function returns NULL; otherwise, it returns the first expression.

How do you handle duplicate records in a query result in SQL?

To handle duplicate records in a query result, you can use the DISTINCT keyword in a SELECT
statement to retrieve unique values from a column or set of columns. Alternatively, you can use
the GROUP BY clause to group the records and perform aggregation functions to eliminate
duplicates.
10

Day 2 - Python Round 1 Questions

What is Python, and why is it useful for data analysis?


Python is a high-level, interpreted programming language known for its simplicity and
readability. It is widely used in data analysis due to its rich libraries, such as Pandas and
NumPy, which facilitate data manipulation, analysis, and visualization.

Explain the difference between a list and a tuple in Python.


A list is a mutable data structure in Python, indicated by square brackets [], allowing for
modification of elements. In contrast, a tuple is an immutable data structure denoted by
parentheses (), meaning its elements cannot be changed once assigned.

How do you create a function in Python?


In Python, you can create a function using the 'def' keyword followed by the function name,
parameters (if any), and a colon. The function body is indented and contains the logic to be
executed when the function is called.

Example:

python

def greet(name):
print("Hello, " + name)
What is the purpose of using 'if' statements in Python?
'If' statements in Python allow for conditional execution of code. They help control the flow of the
program by executing specific blocks of code based on certain conditions being true or false.

Example:

python

x = 10
if x > 5:
print("x is greater than 5")
Explain the concept of a dictionary in Python.
A dictionary in Python is an unordered collection of key-value pairs, enclosed in curly braces {}.
It allows you to store and retrieve data using a unique key for each value, making it easier to
access and manipulate data based on specific keys.

Example:

python
11

student = {
"name": "John",
"age": 25,
"grade": "A"
}
What are the different types of loops in Python, and how are they used?
Python supports various types of loops, including 'for' loops and 'while' loops. 'For' loops are
used to iterate over a sequence, while 'while' loops are used to execute a block of code
repeatedly as long as a specified condition is true.

Example (for loop):

python

fruits = ["apple", "banana", "cherry"]


for x in fruits:
print(x)
Example (while loop):

python

i=1
while i < 6:
print(i)
i += 1

How do you open and read a file in Python?


You can open and read a file in Python using the built-in 'open()' function in combination with the
'read()' or 'readlines()' method to read the content of the file.

Example:

python

file = open("example.txt", "r")


content = file.read()
print(content)
file.close()
Explain the purpose of the 'try' and 'except' blocks in Python.
'Try' and 'except' blocks in Python are used for exception handling. The 'try' block is used to test
a block of code for errors, while the 'except' block is used to handle the errors that occur in the
'try' block.

Example:
12

python

try:
age = int(input("Enter your age: "))
except ValueError:
print("Invalid input. Please enter a valid age.")
How do you import modules in Python?
You can import modules in Python using the 'import' keyword followed by the module name. You
can also use the 'from' keyword to import specific functions or variables from a module.

Example:

python

import math
from datetime import datetime
Explain the purpose of the 'range()' function in Python.
The 'range()' function in Python is used to generate a sequence of numbers within a specified
range. It can be used with 'for' loops to iterate over a specific sequence of numbers.

Example:

python

for x in range(5):
print(x)
What are lambda functions in Python, and how are they used?
Lambda functions in Python are small, anonymous functions that can have any number of
arguments but only one expression. They are often used when a small function is required for a
short period.

Example:

python

x = lambda a, b: a * b
print(x(5, 6))
How do you use the 'map()' and 'filter()' functions in Python?
The 'map()' function is used to apply a specified function to each item in an iterable, while the
'filter()' function is used to filter out elements from an iterable based on a specified condition.

Example (map):
13

python

def square(x):
return x * x
numbers = [1, 2, 3, 4]
squares = list(map(square, numbers))
print(squares)
Example (filter):

python

def is_even(x):
return x % 2 == 0
numbers = [1, 2, 3, 4, 5, 6]
even_numbers = list(filter(is_even, numbers))
print(even_numbers)
Explain the purpose of the 'split()' function in Python.
The 'split()' function in Python is used to split a string into a list of substrings based on a
specified delimiter. By default, the delimiter is a space.

Example:

python

text = "Hello world"


words = text.split()
print(words)
How do you handle exceptions in Python?
Exceptions in Python can be handled using 'try', 'except', 'else', and 'finally' blocks. 'Try' is used
to test a block of code for errors, 'except' is used to handle the error, 'else' is executed if no
errors occur, and 'finally' is executed regardless of whether an error occurs or not.

Example:

python

try:
age = int(input("Enter your age: "))
except ValueError:
print("Invalid input. Please enter a valid age.")
finally:
print("Execution complete.")
What is the purpose of the 'set' data type in Python?
14

The 'set' data type in Python is an unordered collection of unique elements. It is used to perform
mathematical set operations such as union, intersection, and difference.

Example:

python

fruits = {"apple", "banana", "cherry"}


How do you perform string concatenation in Python?
String concatenation in Python is performed using the '+' operator, which combines two or more
strings into a single string.

Example:

python

str1 = "Hello"
str2 = "world"
result = str1 + " " + str2
print(result)
Explain the concept of list comprehension in Python.
List comprehension in Python is a concise way to create lists. It allows you to create a new list
by applying an expression to each item in an existing list.

Example:

python

numbers = [1, 2, 3, 4, 5]
squares = [x * x for x in numbers]
print(squares)

What is the difference between deep copy and shallow copy in Python?
In Python, a shallow copy creates a new object but does not duplicate the nested objects, while
a deep copy creates a new object and recursively duplicates the nested objects.

How do you find the length of a string in Python?


You can find the length of a string in Python using the built-in 'len()' function, which returns the
number of characters in the string.

Example:

python
15

text = "Hello, world!"


print(len(text))
Explain the purpose of the 'strip()' function in Python.
The 'strip()' function in Python is used to remove leading and trailing characters, by default
whitespace characters, from a string. It does not modify the original string but returns a new
string.

Example:

python

text = " Hello, world! "


print(text.strip())
How do you check if a key exists in a dictionary in Python?
You can check if a key exists in a dictionary in Python using the 'in' keyword or the 'get()'
method. The 'in' keyword returns a boolean value, while the 'get()' method returns the value
associated with the key if it exists, otherwise it returns None.

Example:

python

my_dict = {"name": "John", "age": 30}


if "name" in my_dict:
print("Key 'name' exists in the dictionary.")
Explain the purpose of the 'format()' method in Python.
The 'format()' method in Python is used to format strings, allowing you to insert values into
placeholders in a string. It is a convenient way to create formatted output.

Example:

python

name = "John"
age = 30
text = "My name is {} and I am {} years old.".format(name, age)
print(text)
How do you convert a string to lowercase or uppercase in Python?
You can convert a string to lowercase or uppercase in Python using the 'lower()' and 'upper()'
methods, respectively. These methods return a new string and do not modify the original string.

Example:

python
16

text = "Hello, World!"


print(text.lower())
print(text.upper())
Explain the use of the 'append()' method in Python lists.
The 'append()' method in Python lists is used to add an element to the end of a list. It modifies
the original list and does not return any value.

Example:

python

my_list = [1, 2, 3]
my_list.append(4)
print(my_list)
What is the purpose of the 'pop()' method in Python lists?
The 'pop()' method in Python lists is used to remove and return an element from a specific index
or the last element if no index is specified. It modifies the original list.

Example:

python

my_list = [1, 2, 3, 4]
my_list.pop()
print(my_list)
How do you reverse a string in Python?
You can reverse a string in Python using slicing. By specifying a step of -1, you can reverse the
string.

Example:

python

text = "Hello, world!"


reversed_text = text[::-1]
print(reversed_text)
Explain the use of the 'isalpha()' and 'isdigit()' functions in Python.
The 'isalpha()' function is used to check if a string contains only alphabetic characters, and the
'isdigit()' function is used to check if a string contains only digits. Both functions return a boolean
value.

Example:

You might also like