Skip to content

Instantly share code, notes, and snippets.

@santoshpy
Last active February 3, 2019 08:47
Show Gist options
  • Save santoshpy/424deb0127aacec440dd012f423c894b to your computer and use it in GitHub Desktop.
Save santoshpy/424deb0127aacec440dd012f423c894b to your computer and use it in GitHub Desktop.
Interview Sample Question

Interview Sample Question

    1. why is not all memory free when Python exits?
    1. write the output of below code:
   var1 = lambda q: q * 5
   var2 = lambda q: q * 3
   x = 2
   x = var1(x)
   x = var1(x)
   x = var2(x)
   print(x)

Ans: 150

    1. write the output of below code:
class A(object):
  val = 1
 
class B(A):
  pass

class C(A):
  pass

print(A.val, B.val, c.val)
B.val = 20
print(A.val, B.val, c.val)
A.Val = 30
print(A.val, B.val, c.val)

Ans: 1 1 1 1 20 1 30 20 30

    1. Write a Python snippet to find unique element in a list.
    1. write a Python programto reverse all words in a file and write reversed word into another file.
    1. What are Exception Handling ? How do you achieve in python?
    1. Brief explain the following:
    • Inheritance
    • init method
    • String slice
    • String Concation
    • super
    1. Write a python program for below problem:
dict1 = {'fgx23': 23, 'dx22a': 2, 'dsw23': 10, 'as15': 17, 'fk112': 25}
dict2 = {'dx22a': 9, 'dsw23': 1, 'fgx23', 20, 'fk112': 12}

How to add the numbers(value) that have same code(key) in both dictionary? Example: dict1 has key 'dx22a' with value 2 and the dict2 has same 'dx22a' with value 9 the result should be in dict3 with key 'dx22a' with value 11. outputformat:

dict3 = {'fgx23': 43, 'dx2a': 11, 'dsw23': 11, ....etc}
    1. Write a python script that recursivly walks all sub directories and search all files with exentension *jpg, *.jpeg append them into the list Ans:
import os
sub = []
for dirs in os.walk('.'):
    for j in (dirs[2]):
        if j.lower().split('.')[1] in ('jpg','jpeg'):
            sub.append(j)

print(sub)
    1. Explain enumarator , zip and generator funtion in python.
    1. Write a python list comprehension which generate a list of numbers which are odd and divisble by 3 for range n. Ans:
result = [i for i in range(n) if not i%2 == 0 and i%3 == 0] # n can be any positive integers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment