Python Questions
Warm up for Python interview with most asked questions and answers for junior, mid, and senior roles.
What are Keywords in Python?
Show AnswerHide Answer
Python keywords are special reserved words that have specific meanings and purposes and can't be used for anything but those specific purposes.
List the common built-in datatypes in Python?
Show AnswerHide Answer
The following are the common built-in data types in Python:
- Binary Types: memoryview, bytearray, bytes
- Boolean Type: bool
- Set Types: frozenset, set
- Mapping Type: dict
- Sequence Types: range, tuple, list
- Numeric Types: complex, float, int
- Text Type: str
What is a generator in Python?
Show AnswerHide Answer
A generator is a special type of function which does not return a single value, instead, it returns an iterator object with a sequence of values.
What are metaclasses in Python?
Show AnswerHide Answer
A metaclass in Python is a class of a class that defines how a class behaves. A class is itself an instance of a metaclass.
What is GIL?
Show AnswerHide Answer
The Global Interpreter Lock (GIL) is a synchronization mechanism in Python that prevents multiple threads from running Python code at the same time.
What are the different stages of the Life Cycle of a Thread?
Show AnswerHide Answer
The Life Cycle of a Thread is as follows:
- New − A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread.
- Runnable − After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task.
- Waiting − Sometimes, a thread transitions to the waiting state while the thread waits for another thread to perform a task. Thread transitions back to the runnable state only when another thread signals the waiting thread to continue executing.
- Timed Waiting − A runnable thread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the runnable state when that time interval expires or when the event it is waiting for occurs.
- Terminated (Dead) − A runnable thread enters the terminated state when it completes its task or otherwise terminates.