Ilovepdf Merged
Ilovepdf Merged
Examples**. You can copy this into a text editor (like Microsoft Word or Google Docs) and save
it as a PDF.
---
*(PDF Version)*
## **Table of Contents**
---
Python is a **high-level, interpreted, dynamically typed** programming language known for its
**simplicity** and **readability**.
|--------------|------------|-------------|
| **Mutable?** | Yes | No |
**Example:**
```python
```
---
**Example:**
```python
def my_decorator(func):
def wrapper():
print("Before function")
func()
print("After function")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
```
**Output:**
```
Before function
Hello!
After function
```
**Example:**
```python
a = [1, 2, 3]
b=a
c = [1, 2, 3]
print(a == b) # True (same values)
```
**Example:**
```python
print("Args:", args)
print("Kwargs:", kwargs)
example(1, 2, name="Alice")
```
**Output:**
```
Args: (1, 2)
```
### **Q9. What is a lambda function?**
**Example:**
```python
square = lambda x: x ** 2
print(square(5)) # Output: 25
```
**Example:**
```python
class Person:
self.name = name
def __str__(self):
p = Person("Alice")
print(p) # Output: Person: Alice
```
---
- **Global Interpreter Lock (GIL)** allows **only one thread** to execute Python bytecode at a
time.
|--------------|---------------|----------------|
**Example:**
```python
class Meta(type):
dct['version'] = 1.0
class MyClass(metaclass=Meta):
pass
```
**Example:**
```python
def count_up_to(n):
i=1
while i <= n:
yield i
i += 1
```
**Example:**
```python
class MyClass:
def original(self):
return "Original"
def patched(self):
return "Patched"
MyClass.original = patched
obj = MyClass()
```
---
**Example:**
```python
class Animal:
def speak(self):
return "Sound"
class Dog(Animal):
def speak(self):
return "Bark"
dog = Dog()
```
**Example:**
```python
class Cat:
def speak(self):
return "Meow"
class Duck:
def speak(self):
return "Quack"
def animal_sound(animal):
print(animal.speak())
cat = Cat()
duck = Duck()
```
Restricts **direct access** to data (uses `_` or `__` for private variables).
**Example:**
```python
class BankAccount:
def __init__(self, balance):
def get_balance(self):
return self.__balance
account = BankAccount(1000)
```
---
```python
def reverse(s):
return s[::-1]
```
def is_palindrome(s):
return s == s[::-1]
```
```python
def factorial(n):
```
```python
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
fibonacci(5) # Output: 0 1 1 2 3
```
```python
def count_chars(s):
return Counter(s)
```
---
## **Final Notes**
Happy coding! 🚀🐍
Here’s a **comprehensive PDF-ready guide** covering **Data Engineering Interview
Questions** with **Python, AWS, PySpark, SQL, and real-world scenarios**, including
**diagrams, coding exercises, and SQL challenges**:
---
## **Table of Contents**
4. [SQL Mastery](#sql-mastery)
6. [Coding Exercises](#coding-exercises)
---
- **ETL Pipelines**: Use `pandas`, `generators`, and `Dask` for large datasets.
- **Parallel Processing**: `multiprocessing` for CPU-bound tasks.
```python
import pandas as pd
```
|--------------|----------|
---
|--------------|------------|---------------------|
| **S3** | Infinite storage | "How would you optimize S3 for query performance?" |
- **Partitioning**: `s3://bucket/date=2024-01-01/`
---
1. **Partitioning**:
```python
```
2. **Broadcast Join**:
```python
df_large.join(broadcast(df_small), "key")
```
3. **Caching**:
```python
```
---
1. **Window Functions**:
```sql
SELECT user_id,
FROM sales;
```
2. **CTEs vs Subqueries**:
```sql
WITH top_users AS (
```
---
```
```
---
```python
df_sales.groupBy("product_id") \
.agg(F.sum("revenue").alias("total_revenue")) \
.orderBy(F.desc("total_revenue")) \
.limit(10)
```
```sql
SELECT date,
FROM daily_sales;
```
---
```mermaid
graph LR
C --> D[Athena/Redshift]
```
```mermaid
graph LR
B --> C[Firehose]
C --> D[S3]
```
---
## **Final Tips**
Good luck! 🚀
---
**To save as PDF**:
2. Export as **PDF**.