Advanced Python Test - 2

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Vineedk
V
Vineedk
Community Contributor
Quizzes Created: 2 | Total Attempts: 9,327
Questions: 15 | Attempts: 575

SettingsSettingsSettings
Advanced Python Quizzes & Trivia

If you are a programmer then you must have some knowledge on Python. Are you just getting into programming are studying advanced python? This second quiz is designed to gauge your understanding of this language. Give it a try and see how much you score. Good luck!


Questions and Answers
  • 1. 

    What does the following code do? def a(b, c, d): pass

    • A.

      Defines a list and initializes it

    • B.

      Defines a function, which does nothing

    • C.

      Defines a function, which passes its parameters through

    • D.

      Defines an empty class

    Correct Answer
    B. Defines a function, which does nothing
    Explanation
    The given code defines a function named "a" with three parameters, "b", "c", and "d". However, the function does not contain any code or instructions, so it essentially does nothing.

    Rate this question:

  • 2. 

    What gets printed? Assuming python version 2.x print type(1/2)

    • A.

    • B.

      What gets printed? Assuming python version 2.x print type(1/2)

    • C.

    • D.

    • E.

    Correct Answer
    A.
    Explanation
    The code will print "". In Python 2.x, the division operator ("/") performs integer division when both operands are integers. So, 1/2 will result in 0. The type() function is used to determine the type of an object, and in this case, it will return the type "int" for the result of the division.

    Rate this question:

  • 3. 

    What is the output of the following code? print type([1,2])

    • A.

    • B.

    • C.

    • D.

    • E.

    Correct Answer
    E.
    Explanation
    The code will output "". The "type()" function is used to determine the type of an object in Python. In this case, the object is a list containing the elements 1 and 2. The "type()" function returns the type of the object, which is "list" in this case.

    Rate this question:

  • 4. 

    What gets printed? def f(): pass print type(f())

    • A.

    • B.

    • C.

    • D.

    • E.

    Correct Answer
    C.
    Explanation
    The code defines a function called "f" that does not have any code inside it. Then, the code calls the function "f" and tries to print the type of its return value. Since the function "f" does not have a return statement, it will return None by default. Therefore, the code will print "".

    Rate this question:

  • 5. 

    What should the below code print? print type(1J)

    • A.

    • B.

    • C.

    • D.

    • E.

    Correct Answer
    A.
    Explanation
    The code should print "complex" because the function `type()` is used to determine the type of an object, and `1J` represents a complex number in Python.

    Rate this question:

  • 6. 

    What is the output of the following code? print type(lambda:None)

    • A.

    • B.

    • C.

    • D.

    • E.

    Correct Answer
    D.
    Explanation
    The output of the code is "". The code is using the "type()" function to determine the type of the lambda function. In this case, the lambda function is defined as "lambda:None", which means it takes no arguments and returns None. The "type()" function returns the type of the object passed to it, so it returns "".

    Rate this question:

  • 7. 

    What is the output of the below program? a = [1,2,3,None,(),[],] print len(a)

    • A.

      Syntax error

    • B.

      4

    • C.

      5

    • D.

      6

    • E.

      7

    Correct Answer
    D. 6
    Explanation
    The given program creates a list 'a' with 6 elements - 1, 2, 3, None, (), and []. The 'len' function is then used to find the length of the list, which is the number of elements in it. Since the list 'a' has 6 elements, the output of the program will be 6.

    Rate this question:

  • 8. 

    What gets printed? Assuming python version 3.x print (type(1/2))

    • A.

    • B.

    • C.

    • D.

    • E.

    Correct Answer
    C.
    Explanation
    The code will print the type of the result of the division operation, which is a float. In Python 3.x, when dividing two integers, the result will always be a float, regardless of whether the division is exact or not.

    Rate this question:

  • 9. 

    What gets printed? d = lambda p: p * 2 t = lambda p: p * 3 x = 2 x = d(x) x = t(x) x = d(x) print x

    • A.

      7

    • B.

      12

    • C.

      24

    • D.

      36

    • E.

      48

    Correct Answer
    C. 24
    Explanation
    The code defines two lambda functions, d and t, which multiply their input by 2 and 3 respectively. The variable x is initially set to 2. The code then updates the value of x by passing it to the d function, which doubles it to 4. Next, x is passed to the t function, which triples it to 12. Finally, x is passed to the d function again, resulting in a value of 24. Therefore, the value of x that gets printed is 24.

    Rate this question:

  • 10. 

    What gets printed? x = 4.5 y = 2 print x//y

    • A.

      2.0

    • B.

      2.25

    • C.

      9.0

    • D.

      20.25

    • E.

      21

    Correct Answer
    A. 2.0
    Explanation
    The code snippet is using the floor division operator "//" to divide the value of x (4.5) by the value of y (2). Floor division returns the largest integer less than or equal to the result of the division. In this case, 4.5 divided by 2 equals 2.25, and the largest integer less than or equal to 2.25 is 2. Therefore, the code will print 2.0.

    Rate this question:

  • 11. 

    What gets printed? nums = set([1,1,2,3,3,3,4]) print len(nums)

    • A.

      1

    • B.

      2

    • C.

      4

    • D.

      5

    • E.

      7

    Correct Answer
    C. 4
    Explanation
    The code creates a set called "nums" with the values [1, 2, 3, 4]. Since sets only store unique values, any duplicates are automatically removed. The len() function is then used to find the length of the set, which is 4. Therefore, the code will print 4.

    Rate this question:

  • 12. 

    What gets printed? x = True y = False z = False   if x or y and z:     print "yes" else:     print "no"

    • A.

      Yes

    • B.

      No

    • C.

      Fails to compile

    Correct Answer
    A. Yes
    Explanation
    The code will print "yes" because the condition in the if statement is x or (y and z). Since x is True, the entire condition evaluates to True and the code inside the if block is executed.

    Rate this question:

  • 13. 

    What gets printed? x = True y = False z = False   if not x or y:     print 1 elif not x or not y and z:     print 2 elif not x or y or not y and x:     print 3 else:     print 4

    • A.

      1

    • B.

      2

    • C.

      3

    • D.

      4

    Correct Answer
    C. 3
    Explanation
    The correct answer is 3 because the condition "not x or y or not y and x" evaluates to True. This is because the "not x" part is True, the "y" part is True, and the "not y and x" part is also True. Therefore, the code block under this condition will be executed, which is to print 3.

    Rate this question:

  • 14. 

    If PYTHONPATH is set in the environment, which directories are searched for modules? A) PYTHONPATH directory B) current directory C) home directory D) installation dependent default path

    • A.

      A only

    • B.

      A and D

    • C.

      A, B, and C

    • D.

      A, B, and D

    • E.

      A, B, C, and D

    Correct Answer
    D. A, B, and D
    Explanation
    When PYTHONPATH is set in the environment, the directories that are searched for modules include the PYTHONPATH directory, the current directory, and the installation dependent default path. This means that modules can be located in any of these directories and will be accessible when PYTHONPATH is set.

    Rate this question:

  • 15. 

     In python 2.6 or earlier, the code will print error type 1 if accessSecureSystem raises an exception of either AccessError type or SecurityError type try:   accessSecureSystem() except AccessError, SecurityError:   print "error type 1"   continueWork()

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The given code will not print "error type 1" if accessSecureSystem raises an exception of either AccessError type or SecurityError type. This is because the except statement is not written correctly. In Python 2.6 or earlier versions, multiple exceptions should be enclosed in parentheses and separated by commas. Therefore, the correct syntax should be except (AccessError, SecurityError):. Since the except statement is not written correctly, the code will raise a syntax error.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 06, 2013
    Quiz Created by
    Vineedk
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.