Skip to content
My blog

My blog

Just another WordPress site

  • Azure
  • Business Analyst
  • Cybersecurity
  • Java
  • Python
  • Salesforce
  • Snowflake
  • SQL and PLSQL
  • Toggle search form

Python Technical Interview Questions and Answers

Posted on February 1, 2025February 1, 2025 By admin No Comments on Python Technical Interview Questions and Answers
1.What are the key features of Python?

Python is popular because it is:

  • Interpreted – No need for compilation, executed line by line.
  • Dynamically Typed – No need to declare variable types explicitly.
  • Object-Oriented – Supports classes, objects, and inheritance.
  • High-Level – Easy to read and write.
  • Extensive Libraries – Built-in modules for AI, ML, Data Science, etc.
  • Cross-Platform – Runs on Windows, Linux, MacOS.
2.What is the difference between Python 2 and Python 3?
FeaturePython 2Python 3
Print Statementprint "Hello" (no parentheses)print("Hello") (parentheses required)
Division5/2 = 2 (Integer division by default)5/2 = 2.5 (True division)
Unicode StringsStrings are ASCII by defaultStrings are Unicode by default
SupportNo longer maintainedActively maintained
3.What are Python’s data types?

Python provides various built-in data types:

  • Numeric – int, float, complex
  • Sequence – list, tuple, range, str
  • Set – set, frozenset
  • Mapping – dict
  • Boolean – True, False
  • NoneType – None

Example:

x = 10         # int
y = 3.14       # float
z = "Python"   # str
lst = [1, 2, 3] # list
tpl = (4, 5, 6) # tuple
dct = {"key": "value"} # dict
4.What is the difference between a list and a tuple?
FeatureListTuple
DefinitionMutable, ordered collectionImmutable, ordered collection
Syntaxmy_list = [1,2,3]my_tuple = (1,2,3)
PerformanceSlower due to mutabilityFaster as it is immutable
Use CaseWhen modification is neededWhen a fixed sequence is needed

Example:

my_list = [1, 2, 3]
my_list.append(4)  # Allowed

my_tuple = (1, 2, 3)
my_tuple[0] = 10  # TypeError (Tuples are immutable)
5.What is the difference between deep copy and shallow copy?
  • Shallow Copy: Copies references to objects (changes affect both copies).
  • Deep Copy: Creates a completely independent copy.

Example:

import copy

list1 = [[1, 2], [3, 4]]
shallow = copy.copy(list1)
deep = copy.deepcopy(list1)

list1[0][0] = 99

print(shallow)  # [[99, 2], [3, 4]] (Changed)
print(deep)     # [[1, 2], [3, 4]] (Unchanged)
6.What is Python’s lambda function?

A lambda function is an anonymous function defined with the lambda keyword.

Example:

square = lambda x: x * x
print(square(5))  # Output: 25
7. What is the difference between is and ==?
  • == compares values of objects.
  • is compares memory locations (whether they are the same object).

Example:

a = [1, 2, 3]
b = [1, 2, 3]
c = a

print(a == b)  # True (Same values)
print(a is b)  # False (Different objects)
print(a is c)  # True (Same object)
8.What is Python’s garbage collection mechanism?

Python has automatic memory management using reference counting and garbage collection.

  • Uses reference counting to track objects.
  • If an object has zero references, it gets deleted.
  • Garbage collector (gc module) removes circular references.

Example:

import gc
gc.collect()  # Manually trigger garbage collection
9.What is the difference between @staticmethod, @classmethod, and instance methods?
TypeDefined UsingAccessUse Case
Instance Methoddef method(self)self (instance)Accesses instance data
Class Method@classmethod def method(cls)cls (class)Modifies class attributes
Static Method@staticmethod def method()No self or clsUtility function (no instance/class data needed)

Example:

class MyClass:
    def instance_method(self):
        return "Instance method called", self

    @classmethod
    def class_method(cls):
        return "Class method called", cls

    @staticmethod
    def static_method():
        return "Static method called"

obj = MyClass()
print(obj.instance_method())  # Instance method
print(MyClass.class_method())  # Class method
print(MyClass.static_method()) # Static method
10.What is the difference between append() and extend() in Python?
  • append() adds one element to the list.
  • extend() adds multiple elements (iterable) to the list.

Example:

lst = [1, 2, 3]
lst.append([4, 5])
print(lst)  # [1, 2, 3, [4, 5]] (Nested list)

lst = [1, 2, 3]
lst.extend([4, 5])
print(lst)  # [1, 2, 3, 4, 5] (Flattened)
11.What are Python generators?

A generator is a special function that returns an iterator using yield.

  • Uses yield instead of return.
  • Saves memory since it doesn’t store all values in memory.

Example:

def my_generator():
    yield 1
    yield 2
    yield 3

gen = my_generator()
print(next(gen))  # 1
print(next(gen))  # 2
12.What is the difference between map(), filter(), and reduce()?
FunctionPurposeExample
map()Applies a function to all elementsmap(lambda x: x*2, [1,2,3]) → [2,4,6]
filter()Filters elements based on a conditionfilter(lambda x: x>2, [1,2,3]) → [3]
reduce()Applies cumulative operationreduce(lambda x,y: x+y, [1,2,3]) → 6

Example:

from functools import reduce

nums = [1, 2, 3, 4]
print(list(map(lambda x: x*2, nums)))  # [2, 4, 6, 8]
print(list(filter(lambda x: x % 2 == 0, nums)))  # [2, 4]
print(reduce(lambda x, y: x + y, nums))  # 10
Python

Post navigation

Previous Post: Top 10 Core Java Interview Questions and Answers
Next Post: SNOWFLAKE SCHEMA VS STAR SCHEMA WHICH ONE IS BETTER

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • DATA SCIENCE TOP MOST IMPORTANT QUESTION & ANSWERS
  • Understanding Snowflake Architecture: A Deep Dive for Developers
  • Overview of Cloud Computing and Introduction to Microsoft Azure
  • Introduction to Salesforce
  • DATA SHARING & CLONING IN SNOWFLAKE

Recent Comments

No comments to show.

Archives

  • March 2025
  • February 2025
  • January 2025

Categories

  • Azure
  • Business Analyst
  • Cybersecurity
  • Data Science
  • DBT
  • Java
  • Python
  • Salesforce
  • Snowflake
  • SQL and PLSQL

Copyright © 2024 blog.ndredtech.com– All Rights Reserved 

Copyright © 2025 blog.ndredtech.com All Rights Reserved

Powered by PressBook Masonry Blogs