[go: up one dir, main page]

0% found this document useful (0 votes)
2 views3 pages

Python Interview Questions Answers

The document outlines key features of Python, including its data types, mutable and immutable types, and the differences between various data structures like lists, tuples, and dictionaries. It also covers advanced concepts such as decorators, generators, exception handling, and the Global Interpreter Lock (GIL). Additionally, it explains the differences between Python 2 and Python 3, the use of virtual environments, and the importance of PEP 8 for code style.

Uploaded by

narensteve98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python Interview Questions Answers

The document outlines key features of Python, including its data types, mutable and immutable types, and the differences between various data structures like lists, tuples, and dictionaries. It also covers advanced concepts such as decorators, generators, exception handling, and the Global Interpreter Lock (GIL). Additionally, it explains the differences between Python 2 and Python 3, the use of virtual environments, and the importance of PEP 8 for code style.

Uploaded by

narensteve98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Q: What are Python's key features?

A: Python is easy to learn, open-source, interpreted, dynamically typed, has extensive libraries,

supports OOP and functional programming, and is platform-independent.

Q: What is the difference between list, tuple, and set in Python?

A: Lists are mutable and ordered. Tuples are immutable and ordered. Sets are mutable but

unordered and do not allow duplicates.

Q: What is a dictionary in Python? How is it different from a list?

A: A dictionary stores key-value pairs, while a list stores ordered items. Dictionaries are accessed by

keys, lists by indices.

Q: What are mutable and immutable types in Python? Give examples.

A: Mutable types can be changed (e.g., list, dict, set). Immutable types cannot be changed (e.g., int,

str, tuple).

Q: What are Python's data types?

A: Common data types include int, float, str, bool, list, tuple, set, dict, NoneType, and complex.

Q: What are *args and **kwargs in Python functions?

A: *args is used to pass variable number of positional arguments, **kwargs is used for keyword

arguments.

Q: What is the difference between is and = operators?

A: '=' assigns a value, 'is' checks object identity (same memory location).

Q: What are Python's namespaces?

A: A namespace is a container where names are mapped to objects. Types: Local, Global, Built-in,

and Enclosing.

Q: What is PEP 8 and why is it important?

A: PEP 8 is Python's style guide. It ensures code readability, consistency, and best practices.

Q: Explain Python's memory management.

A: Python uses reference counting and a garbage collector to manage memory automatically.

Q: What are Python decorators? How do you use them?


A: Decorators modify function behavior without changing its code. They are used with '@' above the

function definition.

Q: What is a lambda function? How is it different from a normal function?

A: Lambda is an anonymous function with a single expression. Normal functions are defined using

'def' and can have multiple statements.

Q: What is the difference between shallow copy and deep copy?

A: Shallow copy copies references to objects. Deep copy copies the object and all nested objects

recursively.

Q: What is a generator in Python? How is it different from an iterator?

A: Generators yield items using 'yield' and are more memory-efficient. Iterators require __iter__()

and __next__() methods.

Q: Explain list comprehension with an example.

A: [x for x in range(5) if x % 2 == 0] creates [0, 2, 4]. It's a concise way to create lists.

Q: What is the difference between @staticmethod and @classmethod?

A: @staticmethod doesn't access class or instance. @classmethod takes cls as parameter and

accesses class state.

Q: How is exception handling done in Python?

A: Using try-except-finally blocks to handle errors gracefully and maintain flow.

Q: What are Python modules and packages? How do you create them?

A: Modules are .py files. Packages are folders with __init__.py. Create by saving code in files and

directories.

Q: What is the difference between Python 2 and Python 3?

A: Python 3 supports Unicode by default, has better syntax, and is the future; Python 2 is outdated.

Q: What is a virtual environment and why do we use it?

A: It isolates project dependencies, avoiding conflicts between packages in different projects.

Q: What are metaclasses in Python?

A: Metaclasses define behavior of classes. They control class creation using type or custom
metaclass.

Q: Explain the Global Interpreter Lock (GIL).

A: GIL allows only one thread to execute Python bytecode at a time, affecting multi-threading

performance.

Q: What are Python's data structures and how are they implemented?

A: Common ones: list (dynamic array), dict (hash map), set (hash table), tuple (immutable list).

Q: How does Python manage memory (reference counting, garbage collection)?

A: Uses reference counting and cycles are handled by the garbage collector using generational GC.

Q: Explain multithreading vs multiprocessing in Python. How do they work?

A: Multithreading runs threads in one process, limited by GIL. Multiprocessing runs separate

processes using multiple CPUs.

You might also like