Python Interview Questions and Answers
Related differences
Ques 66. How to remove values from a Python array?
The elements can be removed from a Python array using the remove() or pop() function. The difference between pop() and remove() will be explained in the below example.
Example of remove():
fruits = ['apple', 'banana', 'cherry']
fruits.remove('banana')
print(fruits)
Output:
['apple', 'cherry']
Example of pop():
fruits = ['apple', 'banana', 'cherry']
fruits.pop(1)
print(fruits)
Output:
['apple', 'cherry']
Ques 67. How can we access a module written in Python from C?
We can access the module written in Python from C by using the following method.
Module == PyImport_ImportModule("<modulename>");
Ques 68. How do you copy an object in Python?
To copy objects in Python we can use methods called copy.copy() or copy.deepcopy().
Example:
fruits = ["apple", "banana", "cherry"]
x = fruits.copy()
print(x)
Output:
['apple', 'banana', 'cherry']
Ques 69. How do we reverse a list in Python?
By using the list.reverse(): we can reverse the objects of the list in Python.
Ques 70. What is the procedure to install Python on Windows and set path variables?
We need to implement the following steps to install Python on Windows, and they are:
- First, you need to install Python from https://www.python.org/downloads/
- After installing Python on your PC, find the place where it is located in your PC using the cmd python command.
- Then visit advanced system settings on your PC and add a new variable. Name the new variable as PYTHON_NAME then copy the path and paste it.
- Search for the path variable and select one of the values for it and click on ‘edit’.
- Finally, we need to add a semicolon at the end of the value, and if the semicolon is not present then type %PYTHON_NAME%.
Most helpful rated by users:
- What is Python?
- How do I share global variables across modules?
- How do you set a global variable in a function in Python?
- Why can't I use an assignment in an expression?
- What are the rules for local and global variables in Python?