Sunday, July 24, 2016

Python Interview Questions


(1) What is Python?
     Bill Gates -- put DOS on every PC drive hardware, low level hardware language
     Steve Job -- human activity translate to App, c language 
     Zuckerberg -- The one killer app, Html/mobile native.

 Python -- high level, fit data science, if/while/for/function, class, iterator, 
.py runs on all OS/Hardware by translate into low level language 

(2) Write a function def print_directory_contents(sPath):

def print_directory_contents(sPath):
    import os                                       
    for sChild in os.listdir(sPath):                
        sChildPath = os.path.join(sPath,sChild)
        if os.path.isdir(sChildPath):
            print_directory_contents(sChildPath)
        else:
            print(sChildPath)


(3) How do you keep track of different versions of your code?

(4) Output of the following 
def f(x,l=[]):
    for i in range(x):
        l.append(i*i)
    print(l)

(5) Describe Python's garbage collection mechanism in brief.

(6) what is profiling package ?

import cProfile
lIn = [random.random() for i in range(100000)]
cProfile.run('f1(lIn)')
cProfile.run('f2(lIn)')
cProfile.run('f3(lIn)')

def f2(lIn):
    l1 = [i for i in lIn if i<0.5]
    l2 = sorted(l1)
    return [i*i for i in l2]

1 comment:

  1. Hi Buddie,


    I love all the posts, I really enjoyed.
    I would like more information about this, because it is very nice., Thanks for sharing.
    I am scratching my hairs and trying to find out why I am always having such error.

    I have sybpydb installed on my laptop (win 7 professional) in c drive: C:\FAST\anaconda\python27\win64\431\Lib\site-packages\.
    I had set the path to that location: C:\FAST\anaconda\python27\win64\431\Lib\site-packages\.

    But whenever I try to import sybpydb, i am always getting this error message:
    Python Code: (Double-click to select all)
    1
    2
    3
    4
    5 >>> import sybpydb

    Traceback (most recent call last):
    File "", line 1, in
    ImportError: No module named sybpydb


    Great effort, I wish I saw it earlier. Would have saved my day :)


    Gracias
    Irene Hynes

    ReplyDelete