Skip to main content

Python interview questions. Part II. Middle



Questions

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 module.py)

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 *
    print(f"{bar()}")

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

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

    def getAge(self):
        print(__name__)

p = Person("John")
p.getAge()

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):
    print(x,)

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))))) 



Comments

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

Nindo Education LLP Hiring Drive 2024 For Data Analyst Trainee | Location Mumbai

  Nindo Education LLP Hiring Drive 2024:  Nindo Education LLP Hiring Drive 2024 for its Data Analyst Trainee. Nindo Education LLPDrive organizes off-campus drives for candidates in any batch. To apply, candidates should have a bachelor’s degree. if you are interested, please apply as soon as possible. Company Name: Nindo Education LLP Role: Data Analyst Trainee Location: Mumbai Experience: 0-1 years Qualification: Bachelor’s degree Batch: Any Job Type: Full Time Salary: ₹ 4,00,000 – 5,00,000 Nindo Education LLP Hiring Drive 2024 Job Description: As a data analyst trainee at Nindo Education LLP, you will have the opportunity to work with a dynamic team and gain hands-on experience in the field of data analytics. We are looking for a candidate who is proficient in Python, R Programming, Power BI, and Tableau, and has a strong understanding of data analytics concept Responsibility: Assist in collecting, organizing, and analyzing data from various sources to provide insights and recommenda