Python interview questions
Hello Friends,
Today in this article we are going to discuss about some basic questions about python so that it will help us in python so that it will help you in python.
- What is difference between
print(mydict.get())
print(mydict[])
2. Can we add list in the set?
3. What will the Output of –
s = set()
s.add(20)
s.add(20.0)
s.add("20")
4. What will be the solution of this error
pip is not recognized
5. Write a code in terminal to get the current version of python you are using?
6. Write a program to print excel sheet in Python?
7. Create a blank GUI in Python?
8. Write a program to print multiple lines in Python?
9. Write a program to print the factorial number?
10. What is the difference between list and tuples in Python?
Solutions
Q1 solution
When we use dict([]) function and we enter a word which is not present in dictionary it gives the error
![Fig-1 How dict([]) gives an error when we enter a word which is not present in the dictionary](https://i0.wp.com/knowledge-junction.in/wp-content/uploads/2022/03/im1.png?resize=775%2C618&ssl=1)
When we use dict.get() and enter a word which is not present it do not gives the error

Q2 solution
No we cannot add a list into the set. A set is an unordered and immutable collection of values or objects, and a list is an ordered and mutable collection of objects.
Q3 solution
The output will be –

It will return only two values because the value of 20.0 and 20 is same
Q4 solution
- Press Windows key + R to open up a Run dialog box. Then, type “sysdm.cpl” and press Enter to open up the System Properties screen.

2. In the Environment Variables screen, go to System variables and click on Path to select it. Then with the Path selected, click the Edit… button.

In the Edit environment variable screen, click on New and add the path where the PiP installation is located. For Python 3.10, the default location is C:\Python34\Scripts. And then click on ok

Now, finally you have added the pip to check we can open our terminal and type pip. The result will be –

You can also install any package from pip. If you wanna learn more about pip click here
Q5 solution
python --version

Q6 solution
To get the solution check this link’s – part 1 – https://knowledge-junction.in/2021/08/22/python-how-to-read-the-complete-excel-file-using-xlrd/
part 2 – https://knowledge-junction.in/2021/08/22/python-how-to-read-the-complete-excel-file-using-xlrd/
Q7 solution
Code-
from tkinter import*
start=Tk()
start.mainloop()
Output

Q8 solution
print('''Today in this article we are going to
discuss about some basic questions about python
so that it will help us in python.''')
Here we have use triple quotes
Output

Q9 solution
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Q10 solution
Difference between List and Tuple
| LIST | TUPLES |
|---|---|
| Lists are mutable (they can be edited.) | Tuples are immutable (tuples are lists which can’t be edited). |
| Lists are slower than tuples. | Tuples are faster than list. |
| Syntax: list_1 = [10, ‘Knowledge’, 20] | Syntax: tuple_1 = (10, ‘Knowledge’, 20) |
Thanks for reading 📖
Have a nice day 🙂

You must be logged in to post a comment.