Interview Questions

AJAX Interview Questions Android Interview Questions Angular 2 Interview Questions AngularJs Interview Questions Apache Presto Interview Questions Apache Tapestry Interview Questions Arduino Interview Questions ASP.NET MVC Interview Questions Aurelia Interview Questions AWS Interview Questions Blockchain Interview Questions Bootstrap Interview Questions C Interview Questions C Programming Coding Interview Questions C# Interview Questions C++ Interview Questions Cakephp Interview Questions Cassandra Interview Questions CherryPy Interview Questions Clojure Interview Questions Cobol Interview Questions CodeIgniter interview Questions CoffeeScript Interview Questions Cordova Interview Questions CouchDB interview questions CSS Buttons Interview Questions CSS Interview Questions D Programming Language Interview Questions Dart Programming Language Interview Questions Data structure & Algorithm Interview Questions DB2 Interview Questions DBMS Interview Questions Django Interview Questions Docker Interview Questions DOJO Interview Questions Drupal Interview Questions Electron Interview Questions Elixir Interview Questions Erlang Interview Questions ES6 Interview Questions and Answers Euphoria Interview Questions ExpressJS Interview Questions Ext Js Interview Questions F# Interview Questions Firebase Interview Questions Flask Interview Questions Flex Interview Questions Fortran Interview Questions Foundation Interview Questions Framework7 Interview Questions FuelPHP Framework Interview Questions Go Programming Language Interview Questions Google Maps Interview Questions Groovy interview Questions GWT Interview Questions Hadoop Interview Questions Haskell Interview Questions Highcharts Interview Questions HTML Interview Questions HTTP Interview Questions Ionic Interview Questions iOS Interview Questions IoT Interview Questions Java BeanUtils Interview Questions Java Collections Interview Questions Java Interview Questions Java JDBC Interview Questions Java Multithreading Interview Questions Java OOPS Interview Questions Java Programming Coding Interview Questions Java Swing Interview Questions JavaFX Interview Questions JavaScript Interview Questions JCL (Job Control Language) Interview Questions Joomla Interview Questions jQuery Interview Questions js Interview Questions JSF Interview Questions JSP Interview Questions KnockoutJS Interview Questions Koa Interview Questions Laravel Interview Questions Less Interview Questions LISP Interview Questions Magento Interview Questions MariaDB Interview Questions Material Design Lite Interview Questions Materialize CSS Framework Interview Questions MathML Interview Questions MATLAB Interview Questions Meteor Interview Questions MongoDB interview Questions Moo Tools Interview Questions MySQL Interview Questions NodeJS Interview Questions OpenStack Interview Questions Oracle DBA Interview Questions Pascal Interview Questions Perl interview questions Phalcon Framework Interview Questions PhantomJS Interview Questions PhoneGap Interview Questions Php Interview Questions PL/SQL Interview Questions PostgreSQL Interview Questions PouchDB Interview Questions Prototype Interview Questions Pure CSS Interview Questions Python Interview Questions R programming Language Interview Questions React Native Interview Questions ReactJS Interview Questions RequireJs Interview Questions RESTful Web Services Interview Questions RPA Interview Questions Ruby Interview Questions Ruby on Rails Interview Questions SAS Interview Questions SASS Interview Questions Scala Interview Questions Sencha Touch Interview Questions SEO Interview Questions Servlet Interview Questions SQL Interview Questions SQL Server Interview Questions SQLite Interview Questions Struts Interview Questions SVG Interview Questions Swift Interview Questions Symfony PHP Framework Interview Questions T-SQL(Transact-SQL) Interview Questions TurboGears Framework Interview Questions TypeScript Interview Questions UiPath Interview Questions VB Script Interview Questions VBA Interview Questions WCF Interview Questions Web icon Interview Questions Web Service Interview Questions Web2py Framework Interview Questions WebGL Interview Questions Website Development Interview Questions WordPress Interview Questions Xamarin Interview Questions XHTML Interview Questions XML Interview Questions XSL Interview Questions Yii PHP Framework Interview Questions Zend Framework Interview Questions

Top 30 Python Interview Questions for 2022

1) What is Python?

Python is a high level, interpreted and object-oriented programming language. It is easy to learn and supports multiple programming patterns. It is also known as powerful and versatile scripting language.

2) What are the features of Python?

The features of Python are:
  • Easy to use.
  • Object oriented language.
  • Extensible.
  • Integrated.
  • Interpreted language.
  • Cross platform language.
  • Expressive language.

3) What are the types of applications developed by Python?

Application developed by python is:
    • Audio or Video based applications.
Example: TimPlayer etc.
    • Console based applications.
Example: IPython.
    • Web applications.
Example: Pocoo, PythonWikiEngines etc.
    • Application for images.
Example: Gogh, imgSeek etc.
    • Enterprise applications.
Example: OpenErp, Picalo etc.

4) What are the types of tokens used in Python?

There are following types of tokens used in Python are:
  • Keywords.
  • Identifiers.
  • Literals.
  • Operators.

5) Write a simple program in Python to print “PYHTON EXPERT”?

Example of Python program:
a= "PYTHON EXPERT"    
print a

6) What are the types of keywords used in Python?

The types of keywords used in Python are:
finally True False None
and is for as
asset def else not
return lambda or if
elif class import try

7) What are the types of String supported in Python?

There are two types of String supported in Python are:
  • Single line String.
  • Multi line String.

8) What will be the output of the following code snippet?

x=100    
y=200  
list=[100,200,300,400,500];    
if (x in list):    
    print "x is in given list"    
else:    
    print "x is not in given list"    
if(y not in list):    
    print "y is not given in list"    
else:    
    print "y is given in list"
OUTPUT:
x is in given list
y is given in list

9) What will be the output of the following code snippet?

x=9>4 and 4>2    
print x    
y=2>4 or 1<2    
print y    
z=not(8>4)    
print z
OUTPUT:
True  
True
False

10) What are the types of “Python Operators”?

Types of operator are:
  • Arithmetic Operators.
  • Assignment Operators.
  • Membership Operators.
  • Bitwise Operators.
  • Relational Operators.
  • Logical Operators.
  • Identity Operators.

11) What are the types of comments in Python?

There are two types of comment in Python:
    • Single line comment.
Example: # Single Line Comment.
    • Multiple line comment.
Example: '''Multiple Line Comment.'''

12) What will be the output of the following code snippet?

for i in [10,20,30,40,50]:    
 if i==30:    
 pass    
 print "Pass when value is", i    
 print i,
OUTPUT:
10 20 Pass when value is 30
30 40 50

13) Write a program in Python to swap two variables?

Example of swapping:
x = input('Enter value of x: ')    
y = input('Enter value of y: ')  
temp = x    
x = y    
y = temp    
print('The value of x after swapping: {}'.format(x))    
print('The value of y after swapping: {}'.format(y))

14) Write a program in Python to check the number is odd or even?

Example of odd or even number:
num = int(input("Enter a number: "))    
if (num % 2) == 0:    
   print("{0} is Even number".format(num))    
else:    
   print("{0} is Odd number".format(num))

15) Write a program in Python to check the number is positive, negative or zero?

Example:
num = float(input("Enter a number: "))    
  if num > 0:    
 print("{0} is a positive number".format(num))    
 elif num == 0:    
 print("{0} is zero".format(num))     
 else:    
 print("{0} is negative number".format(num))

16) Who is the developer of Python?

Guido van Rossum is the developer of Python.

17) What is dictionary in Python?

Dictionary: It is the collection of components. The components of dictionary are keys and values. Here the values are retrieved by square bracket.

18) How to create a dictionary in Python?

Example:
>>> dictionary={'name':'Atul Jaiswal','id':7014,'dept':'CSE'}

19) Write the following commands used in dictionary?

The following commands used in dictionary are:
    • Used to create dictionary
dictionary= {'variable':'value'}
    • Used to check the available key and value pairs in dictionary
dictionary
    • Used to check the keys available in dictionary
dictionary.keys()
    • Used to check the values available in dictionary
dictionary.values()

20) What are Tuples?

Tuples: It is the form of collection where the data can be stored. It is also similar to list where data is separated by commas. Tuples are enclosed in parenthesis.

21) How to assign single value to multiple variables in Python?

Example:
a=b=c=7014    
print a    
print b    
print c

22) What are the types of literals available in Python?

The types of literals available in Python are:
  • String literals
  • Numeric literals
  • Boolean literals
  • Special literals
  • Literal Collections

23) What are the types of Numeric literals available in Pyhton?

Numeric literals are of four types:
  • Int(signed integers)
  • Long(long integers)
  • float(floating point)
  • Complex(complex)

24) What is the difference between Object-oriented and Procedure-oriented programming languages?

The difference between Object-oriented and Procedure-oriented programming languages are:
Object-oriented Programming Procedural Programming
The computation is done by using objects. It uses a list of instructions to do computation step by step.
Simulates the real world entity. Doesn’t simulate the real world.
Makes maintenance and development easier. Not easy to maintain the codes when project becomes lengthy.
Example: C++, C#, Java. Example: C, Fortran, Pascal.

25) Which command is used to delete a file in Python?

Command used to delete a file in Pyhton is: os.remove (filename)

26) What is the use of split function in Python?

split function: This function is used to divide a string into shorter strings by using the defined separator. It also gives the list of words present in the string.

27) What is capitalize() function?

capitalize(): This function is used to capitalize the first character of String.

28) How can you copy an object in Python?

You can copy an object in Python by using: copy.copy() or copy.deepcopy()

29) What is docstring in Python?

docstring stands for documentation string. It is a way of documenting functions, modules and classes.

30) What are the types of membership operator used in Python?

The types of membership operator are:
  • in operator
  • not in operator



ADVERTISEMENT
ADVERTISEMENT