Python Interview Questions - 2 | Snaprecruit.com

Python Interview Questions - 2 | Snaprecruit.com

Python interview questions part 2

Python interview questions part 2

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. How are keyword arguments specified in the function heading?

Correct Answer is : two stars followed by a valid identifier

2. How many keyword arguments can be passed to a function in a single function call?

Correct Answer is : zero or more

3. What is the output of the following code? def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])

Correct Answer is : 45352

4. What is the output of the following code? def foo(): return total + 1 total = 0 print(foo())

Correct Answer is : 1

5. What is the output of the following code? def foo(): total += 1 return total total = 0 print(foo())

Correct Answer is : error

6. What is the output of the following code? def foo(x): x = ['def', 'abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))

Correct Answer is : FALSE

7. What is the output of the following code? def foo(i, x=[]): x.append(i) return x for i in range(3): print(foo(i))

Correct Answer is : [0] [0, 1] [0, 1, 2].

8. What is the output of the following code? def foo(k): k = [1] q = [0] foo(q) print(q)

Correct Answer is : [0].

9. How are variable length arguments specified in the function heading?

Correct Answer is : one star followed by a valid identifier

10. Which module in the python standard library parses options received from the command line?

Correct Answer is : getopt

11. What is the type of sys.argv?

Correct Answer is : list

12. What is the value stored in sys.argv[0]?

Correct Answer is : the program’s name

13. How are default arguments specified in the function heading?

Correct Answer is : identifier followed by an equal to sign and the default value

14. How are required arguments specified in the function heading?

Correct Answer is : identifier

15. What is the output of the following code? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))

Correct Answer is : TRUE

16. Where are the arguments received from the command line stored?

Correct Answer is : sys.argv

17. What is the output of the following? def foo(i, x=[]): x.append(x.append(i)) return x for i in range(3): y = foo(i) print(y)

Correct Answer is : [0, None, 1, None, 2, None].

18. Which is the correct operator for power(xy)?

Correct Answer is : X**y

19. Which one of these is floor division?

Correct Answer is : //

20. What is the order of precedence in python? i) Parentheses ii) Exponential iii) Multiplication iv) Division v) Addition vi) Subtraction

Correct Answer is : i,ii,iii,iv,v,vi

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon