Question for interview In Python

         Python interview question     

1. Who developed python and in which year.

Ans. Guido van Rossum in 1980.

2. Python based on which language?

Ans. Python is written in c language.

3. Python is compiled or interpreted?

Ans. Interpreted language and code are executed line by line.

4. How try and accept work?

Ans. When we code but if code is wrong then put code in try and except run if try code is wrong.

5. How to import module.

Ans. Write in the top module name i.e. import math, import random.

6. What are OOPs?

Ans. Object-oriented programming is based on objects rather than functions and procedures. Oops, solve the real-world entities like inheritance, polymorphism, hiding data, etc.

7. Is it possible in the tuple to add an element?

Ans. Yes, first to typecast the tuple into the list then we can add an element in the list then again typecast the list into a tuple.

8. What are the differences in list, tuple, set, and dictionary?

Ans. A list is a collection of ordered data. A tuple is an ordered collection of data. A set is an unordered collection. A dictionary is an unordered collection of data that stores data in key-value pairs.

List allowed duplicate, tuple allowed duplicate, the set does not allow duplicate, and dictionary also allowed duplicate element.

In the dictionary, You can not have duplicate keys in Python, but you can have multiple values associated with a key in Python. If you want to keep duplicate keys in a dictionary, you have two or more different values that you want to associate with the same key in the dictionary.

10. How else for the loop work?

Ans. If the condition in for loop is wrong, it goes on to run the program.

11. How graph is drawn in python?

Ans. With the help of the matplotlib module, first import matplotlib module we can dram graph in python.

Ex. Line plot, Bar graph, Scatter chart, Histogram, etc.

12. How do you open files in python, write, read, and append in file handling?

Ans. In file handling, we open files through the open function and there are many modes in files to read, write, and append. For read(r), write(w) and append(a).

13.  What is the difference between a class and a structure?

Ans. Class: User-defined blueprint from which objects are created. It consists of methods or sets of instructions that are to be performed on the objects.

Structure: A structure is basically a user-defined collection of variables that are of different data types.

14. Why use modules? What is its significance?

Ans. A module allows you to organize your Python code logically. Grouping related code into a module makes the code easier to understand and use. A module is a Python object with arbitrarily named attributes you can bind and reference. Simply, a module is a file consisting of Python code.

15. What is membership in operators?

Ans. In python, there are two types of membership operators.

1. In

2. Not In

It is used to check the element in the list, tuple, etc.

Not In is used to check element is not present in the list or not.