15 Most Important Python Interview Questions
See the Python Interview Questions and answers for Testers also Python Interview Questions for 3 years experienced.
You will get here all the Python interview questions for fresher and Python interview questions javatpoint for free. Scroll down for 3 years experienced Python interview Questions.
Let's start with the python interview questions data scientist.
Question 1 -: What are Data
types? What is Python Built-in Datatypes?
Solution -: A data type specifies which type of
a value a variable can store. Python has the following data types built-in by
default -:
String, integer, float,
complex Numbers, Boolean, Set, Dictionary, and Binary data types.
Question 2. Why are the
following code giving errors-:
print(“hello”)
print(“greetings”)
print(“how
are you all”?
Solution. Inline 2 there is syntax error which is that, that
the indentation is unexpected.
Same inline 3, also there
is an error at the last where the Question mark is typed in place of Round bracket
() .
Question 3. How is
Keywords Different from Identifiers?
Solution 3. Identifiers are the name of any variable, constant,
function or Module and Keywords are the words having specific meaning for interpreters,
they cannot be used as Identifiers or for any other purpose. For example -:
Identifiers
= abc , s12w , india_123 , swap etc.
Keywords=
print , float , str , bool, else etc.
Question 4. What are
variables Why are they important in programs?
Solution 4. Variables
play an important role in a program to make it flexible, rather than Entering
the data directly into a program, a programmer cab use variables to represent
the data.
>>> Math’s
= 87
>>>print(Math’s)
87
>>> # so here Maths is a variable
where we have assigned the value 87.
VARIABLE = VALUE
L-Value = refers to the
left-hand side variable
R-Value = refers to the
Right-hand side value.
Question 5. What are
Mutable and Immutable Type Of Data? List Some of them?
Solution 5, A Mutable
Type of data can be changed After it is created and Immutable type of
data are those which cannot be changed if they are created.
Mutable
Immutable
int
Set
float
List
str
Dict
Question 6. What are Key
Features of python?
Solution 6 .Features
of Python is -:
1. Simple and Easy-:
Python is a simple Language that is easy to learn.
2. Free and Open
Source-: Anybody can use Python without purchasing a license.
3. High Level
Language-: Being a high level language, it can be easily understood by the user
without the need to be a concern with lower-level details.
4. Portable-: Python
codes are machine and platform-independent.
5. Extensible and
Embeddable-: Python program support the usage of C/C++ codes.
6. Standard Library-:
Python standard library contains pre-written tools for programming.
check more Important Python Interview Questions. Python Interview Questions and answers for Testers also, Python interview questions javatpoint
Question 7. Identify the
program -:
Solution 7-: Tuple
being immutable (which cannot be changed once created), an attempt to modify
the element of a tuple yields an error.
Question 8. What are the
negative indices in List?
Solution 8. Accessing
the elements from a List Right to Left is called the Negative Indexing.
You can write this
example-:
0
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
Positive
Indexing
|
C
|
O
|
M
|
P
|
U
|
T
|
E
|
R
|
|
-8
|
-7
|
-6
|
-5
|
-4
|
-3
|
-2
|
-1
|
Negative
indexing
|
Question 9. Find and
write the output of the following code -:
L=["jayes","ramya",
"taruna","suraj"]
for i in L:
print(L)
if L[0]=='t':
break
else:
print("finished")
print("Got it")
Solution 9.
['jayes', 'ramya', 'taruna', 'suraj']
finished
['jayes', 'ramya',
'taruna', 'suraj']
finished
['jayes', 'ramya',
'taruna', 'suraj']
finished
['jayes', 'ramya',
'taruna', 'suraj']
finished
Got it
b)
x=[1,2,3]
counter=0
while counter<len(x):
print(x[counter]*'%')
for y in x:
print(y*'+')
counter+=1
Solution-:
%
+
++
+++
%%
+
++
+++
%%%
+
++
+++
c)
x="apple pear peach"
y=x.split()
for z in y:
if z<'m':
print(str.lower(z))
else:
print(str.upper(z))
Solutions-:
apple
PEAR
PEACH
d)
for x in range(-500,500,100):
print(x)
Solution-:
-500
-400
-300
-200
-100
0
100
200
300
400
Q.10 How will you capitalize the first letter of a string?
solution -:
To capitalize the first letter of the string we use
.title() after the string .
for example, if we want to capitalize the first letter of the " hello world "
then,
print("hello world".title()")
output-: Hello World
Q.1 1 We know Python is all the rage these days. But to be truly accepting of great technology, you must know its pitfalls as well. Would you like to talk about this?
Solution-:
Of course, To be true Of course. To be truly yourself, you must be accepting of your flaws.
Only then can you move forward to work on them. Python has its flaws too:
1. Python’s interpreted nature imposes a speed penalty on it.
2. it is weak in mobile computing, and in browsers.
3. Being dynamically-typed, Python uses duck-typing.
4. This can raise run-time errors.
5. Python has underdeveloped database access layers.
Q.12 Write a program that prints two columns in a table that helps to convert miles into kilometers.
Solutions
n=float(input("Enter the value in miles : "))
conversion= 0.621371
kilometers=n/conversion
print("Miles" , '\t',"Kilometers")
print(n,'\t',kilometers)
Output-:
Miles Kilometers
5 8.046722489462816
Q.13 Find the output of the following programs-:
Dict = {1: 'Geeks', 'name': 'For', 3: 'Geeks'}
# accessing a element using key
print("Accessing a element using key:")
print(Dict['name'])
# accessing a element using key
print("Accessing a element using key:")
print(Dict[1])
Solution-:
Accessing an element using the key:
For
Accessing a element using key:
Geeks
Q.14 Consider the following dictionary-:
VOTE={“BJP”:2500,”CONGRESS”:,2300,”AAP”:1800,”OTHERS”:1000}
Write the complete program to print which national party has won the VIDHAN SABHA election 2018.
Solutions-:
VOTE={"BJP":2500,"CONGRESS":2300,"AAP":1800,"OTHERS":1000}
k=VOTE.keys()
seats=0
for i in k:
m=VOTE[i]
if m>seats:
seats=m
party=i
print("Winner is",party,"with ",seats,"seats")
15 What will be the output of the following code:
Values=[]
for I in range(1,4):
values.append(I)
print(values)
Solutions-:
[1]
[1,2]
[1, 2, 3]
Q.16 Write a program to display the elements of list thrice if it is a number and display the element terminated with ‘#’ if it is not a number
For ex:
LISt=[‘41’,”DROND”,”GIRIRAJ”,’13’,ZARA”]
Output should be:
414141
DROND#
GIRIRAJ#
131313
ZARA#
Solution-:
L=['12','welcome','2','PROGCODE','6']
for i in L :
if i.isdigit():
print(i*3)
else:
print(i,'#')
Conceptual Question:
Write a program to sort the elements(keys) from the dictionary and stored them in a LIST.
For ex:
D={3:”hello”,2:”Python",5:”programmer”,1:”Computer”}
After sorting keys will be in the order 1,2,3,5 should stored in the list L like [1,2,3,5]?
Solutions-:
d={2:'Progcode',1:'Piyush',3:'Python',4:'Java'}
dict=dict(sorted(d.items()))
print(dict)
| For More Interview Questions Comment Below |
6 Comments
Please give complete solution of assessment 2 till question number 16 nd conceptual questions
ReplyDeleteWe will be providing you all the solutions on friday 15-May-2020 . Give this information to your friends also.
DeleteThnks
ReplyDeleteWe will be providing you all the solutions on friday 15-May-2020 . Give this information to your friends also.
DeleteWe will be providing you all the solutions on friday 15-May-2020 . Give this information to your friends also.
ReplyDeleteTnks sir
ReplyDelete