Python interview questions part 9

Python interview questions part 9

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

Total Questions: 20

1. What is the output of the following code, if the time module has already been imported? def num(m): t1 = time.time() for i in range(0,m): print(i) t2 = time.time() print(str(t2-t1))   num(3)

Correct Answer is : 1

2. The output of the code shown below: import time time.asctime()

Correct Answer is : Current date and time

3. What is the output of the code shown below? import time t=(2010, 9, 20, 8, 15, 12, 6) time.asctime(t)

Correct Answer is : Error

4. What is the output of the code shown below? import time t=(2010, 9, 20, 8, 45, 12, 6, 0, 0) time.asctime(t)

Correct Answer is : ‘Sun Sep 20 08:45:12 2010’

5. The sleep function (under the time module) is used to:

Correct Answer is : Pause the code for the specified number of seconds

6. The output of the code shown will be: import time for i in range(0,5): print(i) time.sleep(2)

Correct Answer is : Prints the numbers 0, 1, 2, 3, 4 at an interval of 2 seconds between each number

7. The output of the code shown below is time.struct_time(tm_year=2017, tm_mon=6, tm_mday=25, tm_hour=18, tm_min=26, tm_sec=6, tm_wday=6, tm_yday=176, tm_isdst=0) Code: import time t=time.localtime() print(t) To extract only the year from this, we can use the function:

Correct Answer is : t[0]

8. State whether true or false. s = time.time() t= time.time() s == t

Correct Answer is : FALSE

9. What is the output of the code shown below? def mk(x): def mk1(): print("Decorated") x() return mk1 def mk2(): print("Ordinary") p = mk(mk2) p()

Correct Answer is : Decorated

10. In the code shown below, which function is the decorator? def mk(x): def mk1(): print("Decorated") x() return mk1 def mk2(): print("Ordinary") p = mk(mk2) p()

Correct Answer is : mk()

11. The ______ symbol along with the name of the decorator function can be placed above the definition of the function to be decorated works as an alternate way for decorating a function.

Correct Answer is : @

12. What is the output of the code shown? def ordi(): print("Ordinary") ordi ordi()

Correct Answer is : Address

13. The two snippets of codes shown below are equivalent. State whether true or false. CODE 1 @f def f1(): print(“Hello”) CODE 2 def f1(): print(“Hello”) f1 = f(f1)

Correct Answer is : TRUE

14. What is the output of the following function? def f(p, q): return p%q f(0, 2) f(2, 0)

Correct Answer is : 0

15. What is the output of the code shown below? def f(x): def f1(a, b): print("hello") if b==0: print("NO") return return f(a, b) return f1 @f def f(a, b): return a%b f(4,0)

Correct Answer is : hello

16. What are the output of the code shown below? def f(x): def f1(*args, **kwargs): print("*"* 5) x(*args, **kwargs) print("*"* 5) return f1 def a(x): def f1(*args, **kwargs): print("%"* 5) x(*args, **kwargs) print("%"* 5) return f1 @f @a def p(m): print(m) p("hello")

Correct Answer is : *****

17. The code shown above can work with ____ parameters. def f(x): def f1(*args, **kwargs): print("Sanfoundry") return x(*args, **kwargs) return f1

Correct Answer is : any number of

18. What is the output of the code shown below? def f(x): def f1(*args, **kwargs): print("*", 5) x(*args, **kwargs) print("*", 5) return f1 @f def p(m): p(m) print("hello")

Correct Answer is : hello

19. A function with parameters cannot be decorated. State whether true or false.

Correct Answer is : TRUE

20. Identify the decorator in the snippet of code shown below. def sf(): pass sf = mk(sf) @f def sf(): return

Correct Answer is : mk

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon