---
title: "5 Python and SQL Interview Questions: Smarterp"
description: "This post includes Python and SQL interview questions with code examples and explanations for data engineer interview preparation."
url: https://srinimf.com/2024/02/28/5-python-and-sql-interview-questions-smarterp/
date: 2024-02-28
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2024/02/bellingrath-gardens-alabama-landscape-scenic-158028.jpeg?fit=1880%2C1253&ssl=1
categories: ["Data Science"]
tags: ["Data Science", "Interview Questions", "programming", "PySpark", "Python", "Python and SQL", "sql"]
type: post
lang: en
---

# 5 Python and SQL Interview Questions: Smarterp

These questions were asked in a [Data Engineer interview](https://srinimf.com/2025/09/17/top-10-nike-data-engineer-interview-questions-on-spark-sql-and-delta-lake-2025/) at Smarterp. They are useful for preparing for similar interviews.

![Python and SQL Interview Questions](https://i0.wp.com/srinimf.com/wp-content/uploads/2024/02/pexels-photo-6373542.jpeg?resize=1880%2C1253&ssl=1)*Photo by Monstera Production on Pexels.com*

## Python and SQL [Interview Questions](https://srinimf.com/2024/03/03/6-top-data-engineer-interview-questions-hexware/)

**01. [How to](https://srinimf.com/2023/06/05/how-to-print-sum-of-prime-numbers-in-python/) sum all the values of an integer?**

```
# Code to sum all the integers
a=12345

d=0
for i in str(a):
  d += int(i)
print(d)
```

Output

```
15

** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

**02. [How to](https://srinimf.com/2015/12/15/want-to-know-more-about-import-load-and-special-register-in-db2/) reverse a string?**

```
s="srinivas"
k=s[::-1]print(k)
```

Output

```
savinirs

** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

**03. [How to](https://srinimf.com/2021/11/20/python-program-to-print-name-in-reverse-order/) write Pyspark code, to create a DataFrame using Data and Schema. And, extract only the date from the DateTime column?**

```
from pyspark.sql import SparkSession
from pyspark.sql.types import StructField, StructType,StringType, TimestampType
from pyspark.sql.functions import col, to_date

spark=SparkSession.builder.appName("Date extract").getOrCreate()
schema=StructType(
    [StructField("date_column", StringType(), True)    ])
data = [("2024-02-28 08:30:00",),  # Sample data
        ("2024-02-28 12:45:00",),
        ("2024-02-29 10:15:00",)]df=spark.createDataFrame(data, schema)
df=df.withColumn("date_column", col("date_column").cast(TimestampType()))
df=df.withColumn("Date_only", to_date("date_column"))
df.show()
```

Output

```
+-------------------+----------+
|        date_column| Date_only|
+-------------------+----------+
|2024-02-28 08:30:00|2024-02-28|
|2024-02-28 12:45:00|2024-02-28|
|2024-02-29 10:15:00|2024-02-29|
+-------------------+----------+
```

**04. What is the “get root directory” in PySpark?**

In PySpark, the “root directory” typically refers to the directory from which your Spark application is running. It’s the base directory where your SparkContext or SparkSession is created. [check the link](https://spark.apache.org/docs/latest/api/python/reference/api/pyspark.SparkFiles.getRootDirectory.html) for more information.

**05. Can we modify Tuples and Strings in Python?**

We cannot modify Tuples and String in place. But, we can modify by assigning those to new Tuple and New string.

```
my_tuple=(1,2,3,4)
new_tuple=my_tuple[0:1] + (7,) + my_tuple[2:]print(new_tuple)
```

Output

```
(1, 7, 3, 4)

** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

```
my_string="Amazon Operations"
new_string="India " + my_string[0:]print(new_string)
```

Output

```
India Amazon Operations

** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2024%2F02%2F28%2F5-python-and-sql-interview-questions-smarterp%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2024%2F02%2Fbellingrath-gardens-alabama-landscape-scenic-158028.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=5%20Python%20and%20SQL%20Interview%20Questions%3A%20Smarterp)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2024/02/28/5-python-and-sql-interview-questions-smarterp/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2024/02/28/5-python-and-sql-interview-questions-smarterp/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2024/02/28/5-python-and-sql-interview-questions-smarterp/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2024/02/28/5-python-and-sql-interview-questions-smarterp/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%205%20Python%20and%20SQL%20Interview%20Questions%3A%20Smarterp&body=https%3A%2F%2Fsrinimf.com%2F2024%2F02%2F28%2F5-python-and-sql-interview-questions-smarterp%2F&share=email)
-

### Like this:

Like Loading…
