Python Interview Questions
Explain Python?
Answer: Python is a highly comprehensive, interactive, and object-oriented scriptwriting language. It is specifically developed with the purpose of making the content highly readable among the net surfers. Python makes use of various English keywords other than just punctuations. It also has lesser syntactical constructions like in other languages.
Question: What are the distinct features of Python?
Answer: The distinct features of Python include the following.
- Structured and functional programmings are supported.
- It can be compiled to byte-code for creating larger applications.
- Develops high-level dynamic data types.
- Supports checking of dynamic data types.
- Applies automated garbage collection.
- It could be used effectively along with Java, COBRA, C, C++, ActiveX, and COM.
Question: What is Pythonpath?
Answer: A Pythonpath tells the Python interpreter to locate the module files that can be imported into the program. It includes the Python source library directory and source code directory. know more at Python online training
Question: Can we preset Pythonpath?
Answer: Yes, we can preset Pythonpath as a Python installer.
Question: Why do we use Pythonstartup environment variable?
Answer: We use the Pythonstartup environment variable because it consists of the path in which the initialization file carrying Python source code can be executed to start the interpreter.
Question: What is the Pythoncaseok environment variable?
Answer: Pythoncaseok environment variable is applied in Windows with the purpose to direct Python to find the first case insensitive match in an import statement.
Question: What are the supported standard data types in Python?
Answer: The supported standard data types in Python include the following.
- List.
- Number.
- String.
- Dictionary.
- Tuples.
Question: Define tuples in Python?
Answer: Tuples is a sequence data type in Python. The number of values in tuples are separated by commas.
Question: What is the major difference between tuples and lists in Python?
Answer: There are several major differences between tuples and lists in Python, which include the following:
Question: What are the positive and negative indices?
Answer: In the positive indices are applied the search beings from left to the right. In the case of the negative indices, the search begins from right to left. For example, in the array list of size n the positive index, the first index is 0, then comes 1 and until the last index is n-1. However, in the negative index, the first index is -n, then -(n-1) until the last index will be -1.
Question: What can be the length of the identifier in Python?
Answer: The length of the identifier in Python can be of any length. The longest identifier will violate from PEP – 8 and PEP – 20.
Question: Define Pass statement in Python?
Answer: A Pass statement in Python is used when we cannot decide what to do in our code, but we must type something for making syntactically correct.
Question: What are the limitations of Python?
Answer: There are certain limitations of Python, which include the following:
- It has design restrictions.
- It is slower when compared with C and C++ or Java.
- It is inefficient in mobile computing.
- It consists of an underdeveloped database access layer.
Question: Do runtime errors exist in Python? Give an example?
Answer: Yes, runtime errors exist in Python. For example, if you are duck typing and things look like a duck, then it is considered as a duck even if that is just a flag or stamp or any other thing. The code, in this case, would be A Run-time error. For example, Print “Hackr io”, then the runtime error would be the missing parenthesis that is required by print ( ). know more at python training
Question: Can we reverse a list in Python?
Answer: Yes, we can reserve a list in Python using the reverse() method. The code can be depicted as follows.
Question: Why do we need a break in Python?
Answer: Break helps in controlling the Python loop by breaking the current loop from execution and transfer the control to the next block.
Question: Why do we need a continue in Python?
Answer: A continue also helps in controlling the Python loop but by making jumps to the next iteration of the loop without exhausting it.
Question: Can we use a break and continue together in Python? How?
Answer: Break and continue can be used together in Python. The break will stop the current loop from execution, while jump will take to another loop.
Question: Does Python support an intrinsic do-while loop?
Answer: No Python does not support an intrinsic do-while loop.
Question: How many ways can be applied for applying reverse string?
Answer: There are five ways in which the reverse string can be applied which include the following.
- Loop
- Recursion
- Stack
- Extended Slice Syntax
- Reversed
Question: What are the different stages of the Life Cycle of a Thread?
Answer: The different stages of the Life Cycle of a Thread can be stated as follows.
- Stage 1: Creating a class where we can override the run method of the Thread class.
- Stage 2: We make a call to start() on the new thread. The thread is taken forward for scheduling purposes.
- Stage 3: Execution takes place wherein the thread starts execution, and it reaches the running state.
- Stage 4: Thread wait until the calls to methods including join() and sleep() takes place.
- Stage 5: After the waiting or execution of the thread, the waiting thread is sent for scheduling.
- Stage 6: Running thread is done by executing the terminates and reaches the dead state.
Question: What is the purpose of relational operators in Python?
Answer: The purpose of relational operators in Python is to compare values.
Question: What are assignment operators in Python?
Answer: The assignment operators in Python can help in combining all the arithmetic operators with the assignment symbol. know more at Python online course
Question: Why do we need membership operators in Python?
Answer: We need membership operators in Python with the purpose to confirm if the value is a member in another or not.
Question: How are identity operators different than the membership operators?
Answer: Unlike membership operators, the identity operators compare the values to find out if they have the same value or not.
Question: Describe how multithreading is achieved in Python.
Answer: Even though Python comes with a multi-threading package, if the motive behind multithreading is to speed the code then using the package is not the go-to option.
The package has something called the GIL or Global Interpreter Lock, which is a construct. It ensures that one and only one of the threads execute at any given time. A thread acquires the GIL and then do some work before passing it to the next thread. know more at python online training from India
This happens so fast that to a user it seems that threads are executing in parallel. Obviously, this is not the case as they are just taking turns while using the same CPU core. Moreover, GIL passing adds to the overall overhead to the execution.
Comments
Post a Comment