Skip to main content

Python interview questions. Part II. Middle


Q: What is the output of -12 % 10?

Q: What is the output of -12 // 10?

Q: What is the sequence of call operators in the expression a * b * c?

Q: Why shouldn't you make the default arguments an empty list?

Q: What id() function in Python is for?

Q: What is the yield keyword used for in Python?

Q: What is an iterator in Python? Can you write an example?

Q: What is a generator in Python? How are they different from iterators?

Q: What is the difference between __iter__ and __next__?

Q: How do you create a dictionary that can preserve the order of pairs?

Q: What is a context manager? How are they different from try ... finally?

Q: Which functions must be overridden in a class in order for its instances to implement the context manager protocol?

Q: What is the synchronous code? What is asynchronous code? How to write asynchronous code?

Q: What is unittest module in Python? How to write tests in Python?

Q: What is type checking? Why Python is a strongly typed language? Do we have types in Python?

Q: How can you copy an object in Python? How to make a deep copy?

Q: How memory is managed in Python? Why garbage collector exists in Python?

Q: How the garbage collector works in Python? Describe Python's garbage collection mechanism in brief.

Q: How can you share global variables across modules? Is it a good idea to do that?

Q: What is the __slots__ attribute used in a class for?

Q: What are metaclasses in Python?

Q: How to create a class without a class statement?

Code involving questions

Q: How to check that one tuple contains all elements of another tuple?

Q: What will be the output of the following code?

>>> list = ['a', 'b', 'c', 'd', 'e']
>>> print(list[10:]) # []

Q: How can I reload a previously imported module? (we assume that the module is a file

Q: What will be the output of the following code?

>>> a = [[]]*3
>>> a[1].append(1)
>>> print(a)  # [[1], [1], [1]]

Q: What's wrong with the following code?

def foo():
    from .module import *

Q: The file is located in /usr/lib/python/ The program is run with python /usr/lib/python/ What will the output be?

class Person:
    def __init__(self, name):
        __name__ = name

    def getAge(self):

p = Person("John")

Q: Write a timeit decorator to measure the time of function execution.

Q: Write a decorator that will catch errors and repeat the function a maximum of 3 times (configurable).

Q: What's the output of the following code?

class parent:
    def __init__(self, param):
        self.v1 = param

class child:
    def __init__(self, param):
        self.v2 = param

obj = child(11)
print(obj.v1 + " " + obj.v2)

Q: Fix the following code to make it work.

class Repeater:
class RepeaterIterator:

repeater = Repeater("Hello")
for i in repeater:
    print(i)  # hello

Q: Write code to get unique values from a list of complex types (custom classes). Example: [A(1, "ab"), A(2, "ab"), A(2, "aa"), A(1, "ab)] -> [A(1, "ab"), A(2, "ab"), A(2, "aa")].

Q: We have the following code with the unknown function f(). In f(), we do not want to use a return, instead, we may want to use a generator.

for x in f(5):

The output looks like this:

0 1 8 27 64

Write a function f() so that we can have the output above.

Q: What's the output of the following code?

x = [[0], [1]] 

print(len(' '.join(list(map(str, x))))) 


Popular posts from this blog

Data Analysis Interview Question Basic+Adv

  1.    Behavioral Questions : ·     Tell me about a time when you had to analyze a large set of data. How did you approach it, and what was the outcome? ·       Describe a situation where you had to work on a project with tight deadlines. How did you prioritize your tasks? ·       Can you discuss a time when you faced a significant challenge while working in a team? How did you handle it? 2.    Analytical Questions : ·       How would you determine the success of a new product launch on Amazon? ·       If given sales data, how would you identify trends and make recommendations to improve sales performance? ·       How would you assess the impact of changes in pricing on customer behavior and sales? 3.    Case Study/Problem-Solving Scenarios : ·       Analyze a dataset showing customer purchase behavior on Amazon and suggest strategies to increase customer engagement or retention. ·       Given fluctuating sales figures for a particular product category, what factors would you consider

Bytemetrics Solutions Internship 2024 For Data Analyst / Analysis | Work From Home

  Bytemetrics Solutions Internship 2024:  Bytemetrics Solutions Internship 2024 for its Data Analyst / Analysis. Bytemetrics Solutions Internship Drive organizes off-campus drives for candidates in any batch. To apply, candidates should have a Graduate. if you are interested, please apply as soon as possible. Company Name: Bytemetrics Solutions Role: Data Analyst / Analysis Location: Remote Experience: 0 – 1 years Qualification: Graduate Batch: Any Job Type: Full Time Salary: INR 400,000 – 500,000 Bytemetrics Solutions Internship 2024 Job Description: As a Data Analyst at Color Paper India Pvt Ltd you will have the opportunity to gain hands-on experience in data analysis and contribute to real-world projects. Requirements: Currently enrolled in or recent graduate of a relevant academic program. Strong analytical skills with attention to detail. Proficiency in data analysis tools such as Excel, SQL, or Python (preferred but not required). Excellent communication and teamwork skills. Abi

PubMatic Recruitment 2024 for Software Engineer – Data Analytics

PubMatic Recruitment 2024 for its Software Engineer – Data Analytics, PubMatic Drive is organizing Off Campus Drive for candidates in the 2023 Batch. In order to apply, candidates should have a degree in B.E/B.Tech/MCA Degree. If you are interested, Please apply as soon as possible. Company Name: PubMatic Role: Software Engineer – Data Analytics Location: Pune Experience: Freshers Qualification: B.E/B.Tech/MCA Batch: 2023 Batch Job Type: Full Time Salary: Rs.10LPA(Expected) PubMatic Recruitment 2024 Job Description: PubMatic is hiring candidates who can design and implement next-generation highly scalable, distributed, and low-latency applications. If you get excited building applications and architecture to handle 100’s billions of requests per day, managing millions of requests per second with a creative and fast-paced work environment, competitive pay, great incentives, a culture of teamwork, smart and friendly colleagues, and plenty of opportunity to grow in your career then you sh