The Best Python Interview Questions & Answers 2018 - Know More!
The Best Python Interview Questions & Answers 2018 - Know More!
Blog
Blog (https://mindmajix.com/blog) / Python (https://mindmajix.com/python/) / Python Interview
Questions
If you're looking for Python Interview Questions and Answers for Experienced & Freshers, you are
at right place. There are lot of opportunities from many reputed companies in the world.
According to research Python has a market share of about 4.0%. So, You still have opportunities to
move ahead in your career in Python. Mindmajix offers advanced Python Interview Questions
2018 that helps you in cracking your interview & acquire your dream career as Python Developer.
https://mindmajix.com/python-interview-questions 1/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
Learn how to use Python, from beginner basics to advanced techniques, with online video tutorials taught
by industry experts. Enroll for Free Python Training (https://mindmajix.com/python-training) Demo!
Q. What happens if an error occurs that is not handled in the except block?
The program tenuinates. and an execution trace is sent to sys.stderr.
https://mindmajix.com/python-interview-questions 2/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
Q. What happens when a function doesn’t have a return statement? Is this valid?
Yes, this is valid. The function will then return a None object. The end of a function is de ned by
the block of code being executed (i.e., the indenting) not by any explicit keyword.
Q. Under what circumstances would von use a while statement rather than for?
The while statement is used for simple repetitive looping and the for statement is used when one
wishes to iterate through a list of items, such as database records, characters in a string, etc.
https://mindmajix.com/python-interview-questions 3/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
Q. Use a for loop and illustrate how you would de ne and print the characters in a string out,
one per line.
myString = “I Love Python”
for myChar hi myString:
print myChar
Q. Given the string “I LoveQPython” use afor loop and illustrate printing each character tip to,
but not including the Q.
inyString = “I Love Pijtlzon”
for myCizar in myString:
fmyC’har ==
break
print myChar
Q. Given the string “I Love Python” print out each character except for the spaces, using a for
loop.
inyString = I Love Python”
for myCizar in myString:
https://mindmajix.com/python-interview-questions 4/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
fmyChar == ‘’ ‘’:
continue
print myChar
Q. How to use GUI that comes with Python to test your code?
That is just an editor and a graphical version of the interactive shell. You write or load code and
run it, or type it into the shell.
There is no automated testing.
https://mindmajix.com/python-interview-questions 5/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
https://mindmajix.com/python-interview-questions 6/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
https://mindmajix.com/python-interview-questions 7/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
while 1:
line = sys.stdin.readline()
if not line:
break
msg = msg + line
# The actual mail send
server = smtplib.SMTP(‘localhost’)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
A UNIX-only alternative uses send mail. The location of the send mail program varies between
systems; sometimes it is /usr/lib/sendmail, sometime /usr/sbin/sendmail. The send mail manual
page will help you out. Here’s some sample code:
SENDMAIL = “/usr/sbin/sendmail” # sendmail location
import os
p = os.popen(“%s -t -i” % SENDMAIL, “w”)
p.write(“To: receiver@example.comn“)
p.write(“Subject: testn”)
p.write(“n”) # blank line separating headers from body
p.write(“Some textn”)
p.write(“some more textn”)
sts = p.close()
if sts != 0:
print “Sendmail exit status”, sts
Q. How can I mimic CGI form submission (METHOD=POST)? I would like to retrieve web pages
that are the result of posting a form. Is there existing code that would let me do this easily?
Yes. Here’s a simple example that uses httplib:
#!/usr/local/bin/python
import httplib, sys, time
### build the query string
qs = “First=Josephine&MI=Q&Last=Public”
### connect and send the server a path
httpobj = httplib.HTTP(‘www.some-server.out-there’, 80)
httpobj.putrequest(‘POST’, ‘/cgi-bin/some-cgi-script’)
### now generate the rest of the HTTP headers…
httpobj.putheader(‘Accept’, ‘*/*’)
httpobj.putheader(‘Connection’, ‘Keep-Alive’)
httpobj.putheader(‘Content-type’, ‘application/x-www-form-urlencoded’)
httpobj.putheader(‘Content-length’, ‘%d’ % len(qs))
httpobj.endheaders()
httpobj.send(qs)
### nd out what the server said in response…
reply, msg, hdrs = httpobj.getreply()
https://mindmajix.com/python-interview-questions 8/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
if reply != 200:
sys.stdout.write(httpobj.get le().read())
Note that in general for URL-encoded POST operations, query strings must be quoted by using
urllib.quote(). For example to send name=”Guy Steele, Jr.”:
>>> from urllib import quote
>>> x = quote(“Guy Steele, Jr.”)
>>> x
‘Guy%20Steele,%20Jr.’
>>> query_string = “name=”+x
>>> query_string
‘name=Guy%20Steele,%20Jr.’
Q. Why is that none of my threads are not running? How can I make it work?
As soon as the main thread exits, all threads are killed. Your main thread is running too quickly,
giving the threads no time to do any work.
A simple x is to add a sleep to the end of the program that’s long enough for all the threads to
nish:
import threading, time
def thread_task(name, n):
for i in range(n): print name, i
for i in range(10)
Explore Python Sample Resumes! Download & Edit, Get Noticed by Top Employers!
Download Now! (https://mindmajix.com/python-sample-resumes)
Social Share
(https://www.facebook.com/sharer/sharer.php?
(https://twitter.com/home?
(https://plus.google.com/share?
(https://www.linkedin.com/shareArticle?
u=https://mindmajix.com/python-
status=https://mindmajix.com/python-
url=https://mindmajix.com/python-
mini=true&url=https://mindmajix.com/python-
Call us on Leave a Message
interview-interview-interview-interview-
questions)questions)questions)questions&title=https://mindmajix.com/python-
interview-
Previous (https://mindmajix.com/oracle- Next (https://mindmajix.com/sap-
questions&summary=&source=)
goldengate-interview-questions) successfactors-interview-questions)
https://mindmajix.com/python-interview-questions 9/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
0 Comments Mindmajix
1 Login
Sort by Best
Recommend ⤤ Share
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
ALSO ON MINDMAJIX
SAP Simple Finance Tutorial For Beginners Advanced CheckPoint Interview Questions
And Professionals And Answers 2017
1 comment • 3 months ago 2 comments • 3 months ago
Emily Sophia — The SAP finance tutorial was Rishi Sharma — Please correct the answer to
awesome.. Learnt much more in detail about this question. Your answer is partially
the topic.. Good work.. Keep it up.. incorrect.Q. What is the Packet Flow of
https://mindmajix.com/python-interview-questions 10/11
1/23/2018 The Best Python Interview Questions & Answers 2018 - Know More!
SEARCH
CATEGORIES
Looker (https://mindmajix.com/looker/)
MicroStrategy (https://mindmajix.com/microstrategy/)
SHAREPOINT (https://mindmajix.com/sharepoint/)
RELATED POSTS
https://mindmajix.com/python-interview-questions 11/11