Home >>Interview Questions >Python Interview Questions and Answers

Python Interview Questions and Answers

Python Interview Questions and Answers

Q1. What is PYTHON language and what are the application of python ?

Ans : Python is an example of open source software. It is an shell scripting and interpreted language . Python is a dynamically typed language.

APPLICATION ARE:- Applications of python are Data Analysis, Data Science, Desktop based Application,Website Designing.

Q2. Explain What is the main purpose of PYTHONPATH environment variable ?

Ans : PYTHONPATH has a role similar to PATH. This variable tells Python translator where to locate the module files imported into a program.

Q3. What are the main five supported data types in Python? ?

Ans : There are five supported data types in python language:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionaries

Q4. What is the difference between lists and tuples ?

Lists Tuples
Lists are variable, i.e., they can be edited. These Tuples are immutable that means that are the lists which cannot be edited.
Lists are generally slower than tuples. Tuples are faster than lists.
Syntax: list2 = [20, 'python', 30] Syntax: tuple = (20, 'python' , 30)

Q 5. What Is A String In Python ?

Ans : A string in Python is a order of alpha-numeric characters. They are immutable objects. It means that they don’t allow variation once they get assigned a value. Python provides various methods, such as join(), replace(), or split() to alter strings. But none of these change the original object.

Q 6.Which one of the following is an invalid statement ?

a) abc = 4,500,000
b) a b c = 6000 3000 2000
c) a, b, c= 7000, 3000, 7000
d) a_b_c = 7,330,000
Answer: b

Q 7.What do you understand by Tkinter ?

Ans : Tkinter is an inbuilt Python module that is used to create graphical user interface applications.. We can start using it by importing it in our script.

Q 8.Is indentation optional in Python ?

Ans : Indentation in Python is mandatory and is part of its syntax. All programming languages have few way of defining the scope and limit of the block of codes; in Python, it is indentation. Indentation provides better readability to the code, which is probably why Python has made it mandatory .

Q 9.Which databases are supported by Python ?

Ans : MySQL (Structured) and MongoDB (Unstructured) are the famous databases that are supported in Python. Import the module and start using the functions to interact with the database.

Q 9.Which databases are supported by Python ?

Ans : MySQL (Structured) and PostgreSQL are the famous databases that are supported in Python. Import the module and start using the functions to interact with the database.

Q 10. Write a code to display the current time ?

Ans :

from datetime import datetime
time = datetime.now()
currenttime = time.strftime("%H:%M:%S")
print("Current Time =", currenttime)

Q 11.What is the difference between locals() and globals () ?

Ans : locals function is accessed inside the function and it returns all names that can be accessed locally from that function. Globals function returns all names that can be accessed globally from that function.

Q 12.What is parallel assignment ?

Ans : It is a kind of assignment which swap 2 variables without using 3rd variable.

a=20
b=10
a,b = b,a  
this is a parallel assignment    

Q 13.Difference between python 2x vs 3x ?

Ans :

Python 2x Python 3x
Libraries are not compatible. ibraries are more compatible. than 2x
Print function uses as print"abc". Print function uses as print("abc").
It uses xrange function instead of range function. It uses range function instead of xrange function.
It uses floor value(which neglects the remainder). It uses float value(which accept the remainder).

No Sidebar ads