Top 20 Python interview questions & Answers for fresher as well as experienced developers.

In the 21th century,python is the most valuable and demanding language nowadays.There are top 20 python interview questions and answers are given below which will help to crack the interview for both fresher and experienced developers.

The below python interview questions and answers are written with the help of senior python developers,from the good books,taking feedback from few friends,researching the some official website of python.

Let’s start

What do you mean by python & Also explain its benefits.

Python is an interpreted , high level,object-oriented programming language which runs on the  different platforms such as LINUX,WINDOWS,UNIX and MACINTOSH.

Python was written by Guido Van Rossum in 1991.

Latest version python is 3.8.0b4.

program:

print(“hello world”)

Benefits

There are several benefits of python.

1.We have to write less code as compared to other programming languages.

2.It runs on different platforms such as LINUX,UNIX,WINDOWS and MACINTOSH etc.

3.There is a no access modifiers like other programming languages.

4. It is an open-source ie free to use

5.It provides some library and built structure to write the code easy for the developer.

In which areas python are used ?

Python are used in the different areas such as 

1.Data science(Analyzing the data) 

2.Machine Learning

3.Website & internet development 

4.Games

5.Operating system

6.Image processing and graphics design 

What is PEP 8 ?

PEP stands for Python Enhancement proposal.

PEP 8 is a coding convention or set of rules which guides the developer how to write python code with maximum readability.

It improves  readability and consistency of the python code.

How python code is interpreted ? Explain.

Python is an interpreted programming language.Interpreter converts the one statement of the program to the machine code at a time.so it takes more time as compared to compiler  to execute the code.

What are the difference between Python 2.x and Python 3.x ?

Python 3.x is the advanced version of python 2.x.Print statement  stylising is different.

Python 2.x

Print “hello placement”

Python 3.x

print(“hello placement”)

What is lambda function ?

Lambda function is an anonymous function which can have any number of arguments but only one expression or one statement.

x=lambda a,b :a*b
print(x(4,5))

Output:

20

What do you mean  by pickling and unpickling ?

pickling is the  process of converting objects into the String representation and also save the state of an object into a dump file using dump function.

Unpickling is the reverse process  of pickling i.e. retrieving the string representation  into the objects.

What is the difference between the list and tuple ? 

The main difference between the list and tuple.List is mutable(modifiable) and tuple is an immutable(none-modifiable).

Tuple is faster than the List

Syntax:

List

list=[1,”placement”,2]

Tuple

tuple=(1,”placement”,2)

What are the built-in data types in python ?

There are mutable and immutable data types in python.

Mutable data types

1.Sets

2.List

3.Dictonary

Immutable data types

1.Strings 

2.Tuples

3.Numbers

What are local variable and global variables in python ?

Local variable

When a variable is declared inside the function or not globally  then it is known as local variable.

Example:

def multiply( )
a=10 // This is a local variable
b=20
c=a*b
print(c)
multiply( )

Output:

200

Global variable

When a variable is declared outside the  function then it is known as global variable.

Example:

a=10 //This is a global variable
def multiply( ):
b=20 //
c=a*b
print(c)
multiply( )

Output:

200

What do you mean  negative index in python ?

There are two types of index in python positive and negative index.In case of positive index(non-negative),0 is first index,1 is the second index,2 is the  third index and so on.

In case of negative index,-1 is the last index,-2 is the second last index,-3 is the third last index and so on.

Note:Here index will addresses the item or element.

How to convert Number into a string ?

To convert the number into  a string in python,we use inbuilt function str( ).If you want octal and  hexadecimal representation then we can use oct( ) or hex( ) inbuilt function respectively.

What do you mean by namespace in python ?

It provides a mechanism to make sure that all  the names present in the program are unique without any conflicting.

How we can comment the statement or line of code in python ?

It starts with the # character 

Example:

#print the hello world
print(“hello world”)

Output:

Hello world

What is the difference between range and Xrange ?

Range returns the list and Xrange returns the range objects.Both uses the same memory.

It does not depends on the range size.

Write a program frequency of character in a string 

str=”hello” //Initializing the string 
str_frq={ } //This gives the count of character in a string 
for i in str:
If i in str_frq:
Str_frq[ i ]=str_frq[ i ]+1;
Else
Str_frq[ i ]=1;

#Here printing the string
printf(“String frequency is given ”+str[str_frq])

Output:

{‘h’:1,’l’:2,’o’:1}

What do you mean by decorator in python ?

Decorator is a powerful tool that provides the mechanism to  add additional functionalities to the existing function without any changes to the original function.

How we can generate random number in python ?

import random

random.random( )

It will return the floating number in the range of 0 and 1.

What do you mean by dictionary in python ?

It is basically a sequence of key-value pairs.Each key contains the value.All keys should be unique.Keys and values are separated by colons and every key-values are separated by commas.

Example:

{ ‘a’:1, ’b’:2, ‘c’:3 }

What do you mean by slicing in python ?

Python slicing  provides the mechanism to select a range of items from the sequence of string lists etc.

Syntax

slice(stop)

slice(start,stop,end)

Thanks and regards 

Placement preparation

sumankumar80

Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *