Python interview Questions - Oxino Technologies
What is Python?
- Python is a high-level, interpreted programming language known for its simplicity and readability. It emphasizes code readability and allows developers to express concepts in fewer lines of code than languages like C++ or Java.
What are the key features of Python?
- Some key features include simplicity and readability, easy integration with other languages, extensive standard libraries, and support for object-oriented, imperative, functional, and procedural programming styles.
Explain Python's GIL (Global Interpreter Lock).
- The Global Interpreter Lock is a mutex that protects access to Python objects, preventing multiple native threads from executing Python bytecodes simultaneously. This means Python threads cannot fully utilize multi-core processors.
What are Python decorators?
- Decorators in Python are a powerful way to modify or enhance the behavior of functions or methods without changing their source code. They allow functions to be passed as arguments to other functions and returned as values from other functions.
What is the difference between a shallow copy and a deep copy?
- A shallow copy creates a new object, but instead of copying the objects found in the original, it copies references to those objects. In contrast, a deep copy creates a new object and recursively adds copies of objects found in the original.
Explain list comprehensions in Python.
- List comprehensions provide a concise way to create lists. They consist of an expression followed by at least one
forclause and zero or moreifclauses. The expression is evaluated for each item in the sequence(s) specified in theforclause(s).
- List comprehensions provide a concise way to create lists. They consist of an expression followed by at least one
What is the purpose of the
__init__method in Python classes?- The
__init__method is a special method in Python classes. It is called when an object of the class is instantiated. It initializes the object's attributes and performs any necessary setup for the object.
- The
Explain the difference between
append()andextend()methods for lists.- The
append()method adds its argument as a single element to the end of a list. Theextend()method, on the other hand, iterates over its argument, adding each element to the list, extending the list.
- The
What is the purpose of the
selfkeyword in Python?selfis a convention in object-oriented programming in Python that refers to the instance of the object itself. It is the first parameter of any method in a class and refers to the instance of the class, allowing you to access variables that belong to the class.
How are exceptions handled in Python?
- Exceptions in Python are handled using the
try,except,else, andfinallyblocks. Code that might raise an exception is placed inside thetryblock. If an exception occurs, the code in the correspondingexceptblock is executed. Theelseblock is executed if no exceptions are raised, and thefinallyblock is always executed regardless of whether an exception occurred or not.

Comments
Post a Comment