python interview questions and answers

Hi Guys, Welcome to Proto Coders Point. In this Article. we will look into the most frequently asked interview questions for python developer post, which will help you to get prepared for you amazing job offers.

I have classified Python Interview questions into following section:-

  • python interview questions for freshers
  • python interview questions for experienced

Python Interview Questions for Freshers

1. What is Python?

Python is a General & Interpreted Programming Language . It can be used to build different application using its Tools And Libraries. Python can easily support objects, threads, exception can we handled easily, & memory management is made automatically, that help real-world issues.


2. Why Python ?

Python is General Purpose Language that can be easy to Learn And it is used for Developing Application, Software, Apps And Data Visualization. It can be use Non IT persons also like Banking for to do Day to Day Task.


3. What is Swapcase() Function ?

It is a string’s function which converts all uppercase characters into lowercase and vice versa.

stringValue = “IT IS IN LOWERCASE.”  

print(stringValue.swapcase())  

Output :-  “it is in lowercase.”  


4. How To Remove Whitespaces from string start and end ?

To remove the whitespaces from the string, Python Introduces strip([str]) built-in function. This function return a String by removing Whitespaces. Otherwise returns original string.

Example:

string = "  Proto Coders Point   " #here we have space at start & end
print(string.strip())

Output: Proto Coders Point


5. Python is interpreted Language ? Explain?

Yes, Interpreted Language Execute the Code line by line. Programs written in interpreted language that runs directly on the source code, there is no need to intermediate Compilation.


6. Different types of datatypes In Python?

Datatype is a Type of Data that represent the Classification of Data. In Python we have Different Datatypes Namely:-

  • Numeric Data Type
  1. Integer
  2. Float
  3. Complex
  4. Boolean
  • Sequence Data Type
  1. List
  2. Tuple
  3. Range
  4. String

7. What is List and Tuple ? Explain Difference ?

  • List:- List is Data Structure in python & Store collection of Objects.
  • Tuple:- Tuple is a collection of Python objects separated by commas.
ListTuple
1) List is a Collection of Object, which is used to store multiple data at the same time1) Tuple is sequence a data type in python that can contain elements of different data types
2) List are mutable. i.e. Can be modified Once Declared.2) Tuple are immutable. i.e. cannot be modified Once Declared.
3) Defined With square brackets [].3) Defined With parenthesis ().

8. Difference Between Array and List ?

ArrayList
Array is Collection of homogeneous elements. i.e. same DataType.Array is Collection of heterogeneous elements. i.e. Different DataType.
We need to declare an array before use
No need to declared list
Array Consume less MemoryList Consume Large Memory
Handle Arithmetic operation
Cannot handle arithmetic Operation
It is hard to modify like  addition, Update and deleteEasy Modification can do like  addition, Update and delete

9. What is break, continue, Pass ?

Pass : – The pass keywords is a null operation.  Pass used to execute the empty Piece (block) of Code.

 def my_function():

   # do nothing

   Pass

my_function()    # It Does Not Show Any Error

Break :- The brake Statement terminate the loop immediately and control goes to the Next Statement.

Continue : –  It Ends the Current execution of loop. And control goes to beginning of next iteration


10. Application of Python ?

  • Web Development
  • Games Developments
  • Machine Learning
  • Artificial Intelligence
  • Recommendation System
  • Desktop GUI Application Using Tkinter Library


Python Questions for Experience

11. Attributes in Python ?

Global Attributes :- It is a public variable. This is declared in Global Scope and It can be access using Global Keyword

Private Attributes :- It Can defined By using _ _ (Double Underscore) With Identifier. Ex :- __hello

Protected Attributes :- It Can defined By using _ (Single Underscore) With Identifier. Ex :- _hello


12. What is function ? How to Define?

Function is a block of code that Write at Once and it can be called Anytime in the program after declaration of function.

  • Built-In Functions: copy(), len(), count() are the some built-in functions.
  • User defined Functions: Functions is Created by user .
  • Anonymous functions: Those Function are also called Lambda Function and They are Not Declared by def() Keyword

13. Explain __init__ ?

It is constructor Method, It Can Automatically Called when new object is created and it allocates the memory automatically.


14. What is Lambda Function ?

Lambda Function is a anonymous Function that can declare without def() Keyword. It a Take Any argument in single Expression.

Ex:- mul = lambda a, b : a * b

print(mul(5, 5)) # output => 25


15. Libraries Of Python ?

  • Pandas
  • Numpy
  • Scipy
  • Keras
  • TensarFlow
  • Scikit Learn

16. What is type conversion in Python?

int() – converts any data type into integer type

float() – converts any data type into float type

ord() – converts characters into integer

hex() – converts integers to hexadecimal

oct() – converts integer to octal

tuple() –  convert to a tuple.

set() – This function returns the type after converting to set.

list() – convert any data type to a list type.

dict() – convert a tuple of order (key, value) into a dictionary.

str() – Used to convert integer into a string.


17. What are the different file processing modes supported by Python?

  • Read-only mode (r): Open a file for reading. It is the default mode.
  • Write-only mode (w): Open a file for writing.
  • Read-Write mode (rw): Open a file for reading.
  • Append mode (a): Open for writing, append to the end of the file, if the file exists

18. What are the different types of operators in Python?

Operator have Rich set of Operators for Performing Various Operations.

  • Arithmetic Operators
  • Relational Operators
  • Assignment Operators
  • Logical Operators
  • Membership Operators
  • Identity Operators
  • Bitwise Operators

19. What is dictionary in python?

Dictionary is built in Data Types In Python. Dictionary Contain Value in the form of Key value Pair. It is accessed or Indexed by Key.

my_dict={'Country':'India', 'State':'Maharashtra', 'City':'Pune'}

print(my_dict['Country'])

#Output :- India

print(my_dict['State'])

#Output :- Maharashtra

20. Explain split() and join() functions in Python?

split() function use to Split a String into List by using a delimiter.

join() function to return a new String by Joining 2 String.

Example:-

my_string = "Hello World." 

New_list= my_string .split(' ')   #delimiter is ‘space’ 

print(New_list)   #output: ['Hello', 'World.']

print(' '.join(New_list)) #output: Hello World.