Python interview questions part 8

Python interview questions part 8

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

Total Questions: 20

1. Carefully observe the code and give the answer. def example(a): a = a + '2' a = a*2 return a>>>example("hello")

Correct Answer is : indentation Error

2. What data type is the object below ? L = [1, 23, ‘hello’, 1].

Correct Answer is : list

3. In order to store values in terms of key and value we use what core data type.

Correct Answer is : dictionary

4. The following is displayed by a print function call: tomdickharry Select all of the function calls that result in this output

Correct Answer is : print(‘tom\ndick\nharry’)

5. What is the average value of the code that is executed below ? >>>grade1 = 80>>>grade2 = 90>>>average = (grade1 + grade2) / 2

Correct Answer is : 85

6. Select all options that print hello-how-are-you

Correct Answer is : print(‘hello-‘ + ‘how-are-you’)

7. What is the return value of trunc() ?

Correct Answer is : int

8. The output of the snippet of code shown below is: import datetime d=datetime.date(2016,7,24) print(d)

Correct Answer is : 42940

9. What is the output of the snippet of code shown below? import datetime d=datetime.date(2017,06,18) print(d)

Correct Answer is : Error

10. What is the output of the code shown below if the system date is 18th August, 2016? tday=datetime.date.today() print(tday.month())

Correct Answer is : 8

11. What is the output of the code shown if the system date is 18th June, 2017 (Sunday)? import datetime tday=datetime.date.today() print(tday)

Correct Answer is : 42904

12. What is the output of the code shown below if the system date is 18th June, 2017 (Sunday)? tday=datetime.date.today() print(tday.weekday())

Correct Answer is : 6

13. What is the output of the following code if the system date is 21st June, 2017 (Wednesday)? tday=datetime.date.today() print(tday.isoweekday())

Correct Answer is : 3

14. Point out the error (if any) in the code shown below if the system date is 18th June, 2017? tday=datetime.date.today() bday=datetime.date(2017,9,18) till_bday=bday-tday print(till_bday)

Correct Answer is : 92 days, 0:00:00

15. The value returned when we use the function isoweekday() is ______ and that for the function weekday() is ________ if the system date is 19th June, 2017 (Monday).

Correct Answer is : 1,0

16. Which of the following will throw an error if used after the code shown below? tday=datetime.date.today() bday=datetime.date(2017,9,18) t_day=bday-tday

Correct Answer is : print(t_day.months)

17. What is the output of the code shown below if the system date is: 6/19/2017 tday=datetime.date.today() tdelta=datetime.timedelta(days=10) print(tday+tdelta)

Correct Answer is : 42915

18. The output of both of the print statements is the same. State whether true or false. import datetime dt_1 = datetime.datetime.today() dt_2 = datetime.datetime.now() print(dt_1) print(dt_2)

Correct Answer is : FALSE

19. Which of the following functions can be used to find the coordinated universal time, assuming that the datetime module has already been imported?

Correct Answer is : datetime.datetime.utcnow()

20. What is the output of the code shown below? import time time.time()

Correct Answer is : The number of seconds passed since 1st January, 1970

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon