Professional Documents
Culture Documents
SLK Software Python Interview Questions
SLK Software Python Interview Questions
SLK Software Python Interview Questions
Sorting list
a=[20,40, 10, 5]
print(sorted(a))
2. Enumerate list
a=[20,40, 10, 5]
print(list(enumerate(a)))
e=enumerate(a)
for i, j in e:
print(i, j)
# importing libraries
import numpy as np
import pandas as pd
c1 = pd.Categorical([1, 2, 3, 1, 2, 3])
print ("\n\nc1 : ", c1)
c1 : [1, 2, 3, 1, 2, 3]
Categories (3, int64): [1, 2, 3]
4. Coalesce() in PySpark.
// RDD
rdd.getNumPartitions()
df.coalesce(9)
a = [1, 2, 4, 5]
avg=sum(a)/len(a)
print(avg)
Import numpy as np
a=[1,2,3,45]
print(np.mean(a))
6. Inheritance example.
# Parent class
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
pass
7. Decorator example.
# Decorator function
def uppercase_decorator(func):
def wrapper(text):
result = func(text)
return result.upper()
return wrapper
# Function to be decorated
def greet(name):
return f"Hello, {name}!"
- Uses of Decorators.
- NameError
- ValueError
- TypeError
- IndexError
- SyntaxError
- KeyError
- AttributeError
- EOFError
- ZeroDivisionError
- OverflowError
- ModuleNotFoundError
# Calculate average
average = total_sum / len(numbers)
print("Average:", average)