Python Programming: Toughest Quiz!

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 Vaibhav99aggarwa
V
Vaibhav99aggarwa
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,099
Questions: 60 | Attempts: 1,099

SettingsSettingsSettings
Python Programming: Toughest Quiz! - Quiz

.


Questions and Answers
  • 1. 

     Which of the following is not a keyword?

    • A.

      Eval

    • B.

      Assert

    • C.

      Nonlocal

    • D.

      Pass

    Correct Answer
    A. Eval
    Explanation
    The keyword "eval" is not a valid keyword in Python. It is a built-in function that evaluates and executes a string as Python code. The other options, "assert", "nonlocal", and "pass", are all valid keywords in Python. "assert" is used for debugging and testing purposes, "nonlocal" is used to declare a variable in an outer function scope, and "pass" is a placeholder statement used when no action is required.

    Rate this question:

  • 2. 

    All keywords in Python are in:

    • A.

      Lowercase

    • B.

      UPPER CASE

    • C.

      Capitalized

    • D.

      None of the above

    Correct Answer
    D. None of the above
    Explanation
    In Python, keywords are not in lowercase, uppercase, or capitalized. They are reserved words that have a specific meaning and functionality in the language. Therefore, the correct answer is "None of the above".

    Rate this question:

  • 3. 

    Which one of these is floor division?

    • A.

      /

    • B.

      //

    • C.

      %

    • D.

      None of the above

    Correct Answer
    B. //
    Explanation
    The double forward slash operator "//" represents floor division. Floor division returns the largest integer that is less than or equal to the result of the division. It discards the decimal part of the quotient and gives the whole number result.

    Rate this question:

  • 4. 

    Operators with the same precedence are evaluated in which manner:

    • A.

      Left to Right

    • B.

      Right to Left

    • C.

      Can't say

    • D.

      None of the above

    Correct Answer
    A. Left to Right
    Explanation
    Operators with the same precedence are evaluated from left to right. This means that when there are multiple operators with the same precedence in an expression, the evaluation starts from the leftmost operator and moves towards the right. The order of evaluation is determined by the position of the operators in the expression, with the leftmost operator being evaluated first and the rightmost operator being evaluated last.

    Rate this question:

  • 5. 

    Which of these is not a core data type?

    • A.

      Lists

    • B.

      Dictionaries

    • C.

      Tuples

    • D.

      Classes

    Correct Answer
    D. Classes
    Explanation
    Classes are not considered a core data type in Python. Core data types in Python include lists, dictionaries, and tuples. Classes are used to create custom objects and define their properties and behaviors. They are used for object-oriented programming and are not considered as fundamental data types in Python.

    Rate this question:

  • 6. 

    What will be the output of the following Python Code?     1.>>>str=”hello”     2.>>>str[:2]

    • A.

      He

    • B.

      Lo

    • C.

      Olleh

    • D.

      Hello

    Correct Answer
    A. He
    Explanation
    The given Python code initializes a variable "str" with the value "hello". The expression "str[:2]" is used to extract the substring from index 0 to index 1 (excluding index 2) from the string. Therefore, the output will be "he".

    Rate this question:

  • 7. 

    What is the return type of function id?

    • A.

      Int

    • B.

      Float

    • C.

      Bool

    • D.

      Dict

    Correct Answer
    A. Int
    Explanation
    The return type of the function "id" is "int".

    Rate this question:

  • 8. 

    What error occurs when you execute the following Python code snippet? apple=mango

    • A.

      SyntaxError

    • B.

      NameError

    • C.

      ValueError

    • D.

      TypeError

    Correct Answer
    B. NameError
    Explanation
    The error that occurs when executing the given Python code snippet is a NameError. This error suggests that the variable "mango" has not been defined or assigned a value before it is being assigned to the variable "apple". Hence, the code is unable to find the reference to "mango" and raises a NameError.

    Rate this question:

  • 9. 

    What datatype is the object below? L=[1, 23, “Hello” , 2]

    • A.

      List

    • B.

      Dictionary

    • C.

      Tuple

    • D.

      Array

    Correct Answer
    A. List
    Explanation
    The object L is a list because it is enclosed in square brackets and contains a sequence of elements separated by commas. Lists are a datatype in Python that can hold different types of elements, such as integers, strings, and other objects. In this case, the list L contains the elements 1, 23, "Hello", and 2.

    Rate this question:

  • 10. 

    Which data type use key-value pair?

    • A.

      List

    • B.

      Dictionary

    • C.

      Array

    • D.

      Tuple

    Correct Answer
    B. Dictionary
    Explanation
    A dictionary is a data type that uses key-value pairs. It allows you to store and retrieve values based on a unique key. Each key is associated with a value, and you can use the key to access the corresponding value. This makes dictionaries useful for organizing and accessing data in a structured way. Unlike lists, arrays, and tuples, dictionaries provide a way to store data in a non-sequential manner, making them ideal for tasks such as mapping and indexing.

    Rate this question:

  • 11. 

    Which of the following is not a complex number?

    • A.

      K=2+3j

    • B.

      K=complex(2,3)

    • C.

      K=2+3l

    • D.

      K=2+3J

    Correct Answer
    C. K=2+3l
    Explanation
    The given expression k=2+3l represents a complex number because it has a real part (2) and an imaginary part (3l), where l is a variable. In complex numbers, the imaginary part is a multiple of the imaginary unit i or j. Therefore, all the other options, k=2+3j, k=2+3J, and k=2+3j, are valid complex numbers as they follow the standard notation of a complex number with the imaginary unit.

    Rate this question:

  • 12. 

    What does ~4 evaluate to?

    • A.

      -5

    • B.

      -4

    • C.

      -3

    • D.

      +3

    Correct Answer
    A. -5
    Explanation
    The tilde (~) symbol in JavaScript is the bitwise NOT operator. It performs a bitwise negation on the given number by inverting all the bits. In this case, the given number is 4. In binary representation, 4 is 0100. Applying the bitwise NOT operator to 4 will invert all the bits, resulting in 1011, which is the binary representation of -5. Therefore, ~4 evaluates to -5.

    Rate this question:

  • 13. 

    The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.

    • A.

      True

    • B.

      False

    • C.

      Can't say

    Correct Answer
    A. True
    Explanation
    The expression 4/(3*(2-1)) simplifies to 4/(3*1), which further simplifies to 4/3. On the other hand, the expression 4/3*(2-1) simplifies to 4/3*1, which is also equal to 4/3. Therefore, both expressions result in the same value, making the statement true.

    Rate this question:

  • 14. 

    Which of the following operators has its associativity from right to left?

    • A.

      +

    • B.

      //

    • C.

      %

    • D.

      **

    Correct Answer
    D. **
    Explanation
    The operator that has its associativity from right to left is the exponentiation operator (**). This means that if there are multiple occurrences of this operator in an expression, the evaluation will start from the rightmost occurrence and proceed towards the left. For example, in the expression 2 ** 3 ** 2, the evaluation will be done as 2 ** (3 ** 2), resulting in 2 ** 9 = 512.

    Rate this question:

  • 15. 

    What is the value of the following expression? float (22//3+3/3)

    • A.

      8

    • B.

      8.0

    • C.

      8.3

    • D.

      8.33

    Correct Answer
    B. 8.0
    Explanation
    The expression calculates the value of 22 divided by 3 using integer division (//), which results in 7. Then, it adds the result of 3 divided by 3, which is 1. Finally, it converts the result to a float using the float() function. The final result is 8.0.

    Rate this question:

  • 16. 

    Which of the following expressions is an example of type conversion?

    • A.

      4.0+float(3)

    • B.

      5.3+6.3

    • C.

      5.0+3

    • D.

      3+7

    Correct Answer
    A. 4.0+float(3)
    Explanation
    The expression "4.0+float(3)" is an example of type conversion because it involves converting the integer value 3 into a float value using the "float()" function. This allows for the addition of a float value (4.0) with the converted float value (3.0), resulting in a float value as the final result. Type conversion is the process of changing the data type of a value to perform operations or assignments that require a different data type.

    Rate this question:

  • 17. 

    What will be the output of the following code snippet? bool(‘False’) bool()

    • A.

      True True

    • B.

      False True

    • C.

      False False

    • D.

      True False

    Correct Answer
    D. True False
    Explanation
    The code snippet is trying to create a boolean value from the string 'False'. However, the syntax used is incorrect. The correct syntax for creating a boolean value is bool(). Since the string 'False' is not empty and is not equal to 'True', the output of bool('False') will be True. The output of bool() will be False because it is an empty value.

    Rate this question:

  • 18. 

    What will be the output of the following Python code? class Truth:     pass x=Truth() bool(x)

    • A.

      Pass

    • B.

      True

    • C.

      False

    • D.

      Error

    Correct Answer
    B. True
    Explanation
    The code defines a class called "Truth" but does not have any methods or attributes. It then creates an instance of the class called "x". The bool() function is used to check the truthiness of the object "x". Since "x" is an instance of a class, it is considered truthy, so the output of the code will be True.

    Rate this question:

  • 19. 

    What will be the output of the following Python code? if (9 < 0) and (0 < -9):     print("hello") elif (9 > 0) or False:     print("good") else:     print("bad")

    • A.

      Error

    • B.

      Hello

    • C.

      Good

    • D.

      Bad

    Correct Answer
    C. Good
    Explanation
    The output of the code will be "good" because the condition in the elif statement is true. In the if statement, the first condition (9 < 0) is false, so it is not executed. The second condition (0 < -9) is also false, so the code inside the if statement is not executed. In the elif statement, the first condition (9 > 0) is true, so the code inside the elif statement is executed, resulting in the output "good".

    Rate this question:

  • 20. 

    What will be the output of the following Python code? i = 1 while True:     if i%2 == 0:         break     print(i)     i += 2

    • A.

      1

    • B.

      1 2

    • C.

      1 2 3 4 5 6 

    • D.

      1 3 5 7 9 11

    Correct Answer
    D. 1 3 5 7 9 11
    Explanation
    The given code starts with i=1 and enters an infinite loop. Inside the loop, it checks if i is divisible by 2. Since 1 is not divisible by 2, the condition is false and the break statement is not executed. Therefore, the code continues to print the value of i, which is 1, and then increments i by 2. This process repeats indefinitely, printing odd numbers in ascending order: 1, 3, 5, 7, 9, 11.

    Rate this question:

  • 21. 

    What will be the output of the following Python code? x = ['ab', 'cd'] for i in x:     i.upper() print(x)

    • A.

      [‘ab’, ‘cd’]

    • B.

      [‘AB’, ‘CD’]

    • C.

      [None, None]

    • D.

      None of the mentioned

    Correct Answer
    A. [‘ab’, ‘cd’]
    Explanation
    The code will output ['ab', 'cd']. This is because the code creates a list x with two elements 'ab' and 'cd'. Then, it iterates over each element in the list using a for loop. Inside the loop, the upper() method is called on each element, which converts the element to uppercase. However, since the upper() method returns a new string and does not modify the original string, the changes are not reflected in the list x. Therefore, when the print statement is executed, it prints the original list x as ['ab', 'cd'].

    Rate this question:

  • 22. 

    What will be the output of the following Python code? x = "abcdef" while i in x:     print(i, end=" ")

    • A.

      A b c d e f

    • B.

      Abcdef

    • C.

      Iiiiii…

    • D.

      Error

    Correct Answer
    D. Error
    Explanation
    The code will result in an error. This is because the variable "i" is not defined before the while loop, so the condition "i in x" cannot be evaluated.

    Rate this question:

  • 23. 

    What will be the output of the following Python code? x = "abcdef" i = "a" while i in x[:-1]:     print(i, end = " ")

    • A.

      A a a a a

    • B.

      A a a a a a

    • C.

      A a a a a a …

    • D.

      A

    Correct Answer
    C. A a a a a a …
    Explanation
    The code initializes a variable "x" with the string "abcdef" and another variable "i" with the string "a". The while loop checks if "i" is present in the substring of "x" excluding the last character. Since "i" is present in the substring "abcde", the print statement is executed and "a" is printed. This process continues until "i" is no longer present in the substring. Therefore, the output will be a series of "a" separated by spaces.

    Rate this question:

  • 24. 

    What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values():     print(d[x])

    • A.

      0 1 2

    • B.

      A b c

    • C.

      0 a 1 b 2 c

    • D.

      None of the mentioned

    Correct Answer
    D. None of the mentioned
  • 25. 

    What will be the output of the following Python code? ⦁    class father: ⦁        def __init__(self, param): ⦁            self.o1 = param ⦁      ⦁    class child(father): ⦁        def __init__(self, param): ⦁            self.o2 = param ⦁      ⦁    >>>obj = child(22) ⦁    >>>print "%d %d" % (obj.o1, obj.o2)

    • A.

      None None

    • B.

      None 22

    • C.

      22 None

    • D.

      Error is generated

    Correct Answer
    D. Error is generated
    Explanation
    The code will generate an error because the child class does not have a constructor that calls the constructor of the parent class. Therefore, when the child object is created and the print statement tries to access the attributes o1 and o2, they are not defined, resulting in an error.

    Rate this question:

  • 26. 

    Which one do you like?What will be the output of the following Python code? ⦁    >>>example = "snow world" ⦁    >>>print("%s" % example[4:7])

    • A.

      Wo

    • B.

      World

    • C.

      Sn

    • D.

      Rl

    Correct Answer
    A. Wo
    Explanation
    The code is using string slicing to extract a portion of the string "example". The slicing syntax [4:7] means to start at index 4 and go up to, but not including, index 7. In the string "snow world", the characters at indexes 4, 5, and 6 are "w", "o", and " ", respectively. So, the output will be "wo".

    Rate this question:

  • 27. 

    What will be the output of the following Python code snippet? print('a@ 1,'.islower())

    • A.

      True

    • B.

      False

    • C.

      None

    • D.

      Error

    Correct Answer
    A. True
    Explanation
    The output of the code snippet will be True. This is because the islower() method checks if all characters in the string are lowercase, and in this case, the string "a@ 1," does not contain any uppercase characters. Therefore, the method returns True.

    Rate this question:

  • 28. 

    What will be the output of the following Python code snippet? print('HelloWorld'.istitle())

    • A.

      True

    • B.

      False

    • C.

      None

    • D.

      Error

    Correct Answer
    B. False
    Explanation
    The output of the given code snippet will be False. The istitle() method is used to check if the string is in titlecase format, which means the first character of each word is capitalized and all other characters are in lowercase. In this case, the string "HelloWorld" is not in titlecase format, as it does not have all lowercase characters except for the first character. Therefore, the istitle() method will return False.

    Rate this question:

  • 29. 

    Suppose list1 is [2445,133,12454,123], what is max(list1)?

    • A.

      2445

    • B.

      133

    • C.

      12454

    • D.

      123

    Correct Answer
    C. 12454
    Explanation
    The correct answer is 12454 because it is the largest number in the given list. The function max() is used to find the maximum value in a list, and in this case, it returns 12454 as the largest number in the list [2445, 133, 12454, 123].

    Rate this question:

  • 30. 

     Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?

    • A.

      Print(list1[0])

    • B.

      Print(list1[:2])

    • C.

      Print(list1[:-2])

    • D.

      All of the mentioned

    Correct Answer
    D. All of the mentioned
    Explanation
    All of the mentioned options are correct syntax for slicing operation. The first option, `print(list1[0])`, will print the element at index 0 of the list, which is 4. The second option, `print(list1[:2])`, will print the elements from the start of the list up to index 2 (exclusive), which are [4, 2]. The third option, `print(list1[:-2])`, will print all the elements of the list except the last two, which are [4, 2, 2, 4, 5, 2]. Therefore, all of the mentioned options are correct.

    Rate this question:

  • 31. 

    Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?

    • A.

      [3, 4, 5, 20, 5, 25, 1, 3]

    • B.

      [1, 3, 3, 4, 5, 5, 20, 25]

    • C.

      [3, 5, 20, 5, 25, 1, 3]

    • D.

      [1, 3, 4, 5, 20, 5, 25]

    Correct Answer
    C. [3, 5, 20, 5, 25, 1, 3]
    Explanation
    After executing the code listExample.pop(1), the element at index 1 in listExample is removed. Therefore, the resulting list1 will be [3, 5, 20, 5, 25, 1, 3].

    Rate this question:

  • 32. 

    What will be the output of the following Python code? ⦁    >>>list1 = [1, 3] ⦁    >>>list2 = list1 ⦁    >>>list1[0] = 4 ⦁    >>>print(list2)

    • A.

      [1, 3]

    • B.

      [4, 3]

    • C.

      [1, 4]

    • D.

      [1, 3, 4]

    Correct Answer
    B. [4, 3]
    Explanation
    The output of the code will be [4, 3]. This is because when we assign list1 to list2, we are actually creating a reference to the same list object. So any changes made to list1 will also be reflected in list2. When we change the value of the first element in list1 to 4, it also changes the value in list2. Therefore, the output is [4, 3].

    Rate this question:

  • 33. 

    What will be the output of the following Python code? a=[1,2,3] b=a.append(4) print(a) print(b)

    • A.

      [1,2,3,4] [1,2,3,4]

    • B.

      [1, 2, 3, 4] None

    • C.

      Syntax error

    • D.

      [1,2,3] [1,2,3,4]

    Correct Answer
    B. [1, 2, 3, 4] None
    Explanation
    The code first creates a list `a` with elements [1, 2, 3]. Then, it appends the value 4 to the list `a` using the `append()` method. The `append()` method modifies the list in-place and does not return anything. Therefore, the value of `b` is None. Finally, the code prints the modified list `a`, which is [1, 2, 3, 4], and the value of `b`, which is None.

    Rate this question:

  • 34. 

    What will be the output of the following Python code? s=["pune", "mumbai", "delhi"] [(w.upper(), len(w)) for w in s]

    • A.

      Error

    • B.

      [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]

    • C.

      [PUNE, 4, MUMBAI, 6, DELHI, 5]

    • D.

      [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]

    Correct Answer
    D. [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]
    Explanation
    The given code uses a list comprehension to create a new list. It iterates over each element in the list 's', and for each element, it converts it to uppercase using the 'upper()' method and calculates the length of the string using the 'len()' function. The result is a list of tuples, where each tuple contains the uppercase string and its length. Therefore, the output will be [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)].

    Rate this question:

  • 35. 

    Which of the following is a Python tuple?

    • A.

      [1, 2, 3]

    • B.

      (1, 2, 3)

    • C.

      {1, 2, 3}

    • D.

      {}

    Correct Answer
    B. (1, 2, 3)
    Explanation
    The correct answer is (1, 2, 3) because a tuple in Python is defined by enclosing elements in parentheses. This distinguishes it from a list (option [1, 2, 3]) which uses square brackets, a set (option {1, 2, 3}) which uses curly braces, and an empty dictionary (option {}).

    Rate this question:

  • 36. 

     Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

    • A.

      D.delete(“john”:40)

    • B.

      D.delete(“john”)

    • C.

      Del d[“john”]

    • D.

      Del d(“john”:40)

    Correct Answer
    C. Del d[“john”]
    Explanation
    To delete the entry for "john" in the dictionary, we use the command "del d['john']". This command removes the key-value pair with the key "john" from the dictionary "d".

    Rate this question:

  • 37. 

     Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?

    • A.

      D.size()

    • B.

      Len(d)

    • C.

      Size(d)

    • D.

      D.len()

    Correct Answer
    B. Len(d)
    Explanation
    The len() function is used to obtain the number of entries in a dictionary. In this case, len(d) will return the number of entries in the dictionary d, which is 2.

    Rate this question:

  • 38. 

    What will be the output of the following Python code snippet? 1. d={“john”:40 , “peter”:45} 2. print(list(d.keys()))

    • A.

      [“john”, “peter”]

    • B.

      [“john”:40, “peter”:45]

    • C.

      (“john”, “peter”)

    • D.

      (“john”:40, “peter”:45)

    Correct Answer
    A. [“john”, “peter”]
    Explanation
    The code snippet creates a dictionary "d" with keys "john" and "peter" and their corresponding values. The "print(list(d.keys()))" statement prints the list of keys in the dictionary, which is ["john", "peter"].

    Rate this question:

  • 39. 

    What will be the output of the following Python code? >>> a={'B':5,'A':9,'C':7} >>> sorted(a)

    • A.

      [‘A’,’B’,’C’]

    • B.

      [‘B’,’C’,’A’]

    • C.

      [5,7,9]

    • D.

      [9,5,7]

    Correct Answer
    A. [‘A’,’B’,’C’]
    Explanation
    The code will output a sorted list of the keys in the dictionary 'a'. The keys in the dictionary are 'B', 'A', and 'C', and when sorted, they will be in alphabetical order, resulting in the output ['A', 'B', 'C'].

    Rate this question:

  • 40. 

     What will be the output of the following Python code? >>> a={"a":1,"b":2,"c":3} >>> b=dict(zip(a.values(),a.keys())) >>> b

    • A.

      {‘a’: 1, ‘b’: 2, ‘c’: 3}

    • B.

      An exception is thrown

    • C.

      {‘a’: ‘b’: ‘c’: }

    • D.

      {1: ‘a’, 2: ‘b’, 3: ‘c’}

    Correct Answer
    D. {1: ‘a’, 2: ‘b’, 3: ‘c’}
    Explanation
    The given Python code first creates a dictionary 'a' with keys 'a', 'b', and 'c' and corresponding values 1, 2, and 3. Then, it creates a new dictionary 'b' by swapping the keys and values of dictionary 'a' using the zip() function. The zip() function takes the values of dictionary 'a' as keys and the keys of dictionary 'a' as values, and creates a list of tuples. The dict() function then converts this list of tuples into a dictionary. Therefore, the output of the code will be a dictionary with keys 1, 2, and 3 and corresponding values 'a', 'b', and 'c'.

    Rate this question:

  • 41. 

     What will be the output of the following Python expression? round(4.5676,2)?

    • A.

      4.5

    • B.

      4.6

    • C.

      4.57

    • D.

      4.56

    Correct Answer
    C. 4.57
    Explanation
    The round() function in Python is used to round a number to a specified number of decimal places. In this case, the expression round(4.5676, 2) will round the number 4.5676 to 2 decimal places. The result of this expression will be 4.57.

    Rate this question:

  • 42. 

    Which keyword is used for function?

    • A.

      Fun

    • B.

      Define

    • C.

      Def

    • D.

      Function

    Correct Answer
    C. Def
    Explanation
    The keyword "def" is used for defining a function in programming languages like Python. It is followed by the name of the function and a set of parentheses, which may contain parameters. The "def" keyword signifies the start of a function definition and is essential for creating reusable blocks of code that can be called and executed multiple times within a program.

    Rate this question:

  • 43. 

    What will be the output of the following Python code? ⦁    def printMax(a, b): ⦁        if a > b: ⦁            print(a, 'is maximum') ⦁        elif a == b: ⦁            print(a, 'is equal to', b) ⦁        else: ⦁            print(b, 'is maximum') ⦁    printMax(3, 4)

    • A.

       3

    • B.

      4

    • C.

      4 is maximum

    • D.

      None of the mentioned

    Correct Answer
    C. 4 is maximum
    Explanation
    The given Python code defines a function called `printMax` that takes two parameters `a` and `b`. The code then compares the values of `a` and `b` using conditional statements. If `a` is greater than `b`, it prints `a` followed by "is maximum". If `a` is equal to `b`, it prints `a` followed by "is equal to" followed by `b`. If neither of these conditions is true, it means that `b` is greater than `a`, so it prints `b` followed by "is maximum".

    In the given code, `printMax(3, 4)` is called, so `a` is 3 and `b` is 4. Since `b` is greater than `a`, the output will be "4 is maximum".

    Rate this question:

  • 44. 

    What will be the output of the following Python code? ⦁    x = 50 ⦁    def func(): ⦁        global x ⦁        print('x is', x) ⦁        x = 2 ⦁        print('Changed global x to', x) ⦁    func() ⦁    print('Value of x is', x)

    • A.

      X is 50 Changed global x to 2 Value of x is 50

    • B.

      X is 50 Changed global x to 2 Value of x is 2

    • C.

      X is 50 Changed global x to 50 Value of x is 50

    • D.

      None of the mentioned

    Correct Answer
    B. X is 50 Changed global x to 2 Value of x is 2
    Explanation
    The code starts by assigning the value 50 to the variable x. Then, a function named func is defined. Inside the function, the global keyword is used to indicate that the variable x is a global variable. The function prints the value of x, which is 50 at this point. Then, the value of x is changed to 2 using the assignment statement. The function prints the message "Changed global x to 2". Finally, outside the function, the value of x is printed again, which is 2 now. Therefore, the output of the code will be "x is 50, Changed global x to 2, Value of x is 2".

    Rate this question:

  • 45. 

    Python supports the creation of anonymous functions at runtime, using a construct called __________

    • A.

      Lambda

    • B.

      Pi

    • C.

      Anonymous

    • D.

      None of the mentioned

    Correct Answer
    A. Lambda
    Explanation
    Python supports the creation of anonymous functions at runtime using a construct called "lambda". Lambda functions are small, one-line functions that do not have a name and are defined using the keyword "lambda". They are commonly used when a small function is needed for a short period of time and it is not necessary to define a separate function.

    Rate this question:

  • 46. 

     What will be the output of the following Python code? a=10 b=20 def change():     global b     a=45     b=56 change() print(a) print(b)

    • A.

      10 56

    • B.

      45 56

    • C.

      10 20

    • D.

      Syntax Error

    Correct Answer
    A. 10 56
    Explanation
    The code defines two variables, a and b, with initial values of 10 and 20 respectively. Then, a function called change is defined. Inside the function, the global keyword is used to indicate that the variable b is a global variable. The variable a is assigned a new value of 45, and the variable b is assigned a new value of 56. The change function is then called. Finally, the values of a and b are printed. Since the variable a is not declared as global inside the function, the value of a remains unchanged and is still 10. However, the variable b is declared as global, so the value of b is updated to 56. Therefore, the output of the code is 10 and 56.

    Rate this question:

  • 47. 

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

    • A.

      [0] [1] [2]

    • B.

      [0] [0, 1] [0, 1, 2]

    • C.

      [1] [2] [3]

    • D.

      [1] [1, 2] [1, 2, 3]

    Correct Answer
    B. [0] [0, 1] [0, 1, 2]
    Explanation
    The function foo takes two parameters, i and x, with x having a default value of an empty list. Inside the function, the value of i is appended to the list x using the append method. The function then returns the modified list x.

    In the given code, a for loop is used to iterate over the range from 0 to 2. In each iteration, the foo function is called with the current value of i. The output of each function call is printed.

    Since the default value of x is an empty list, the first function call foo(0) will append 0 to the empty list and return [0]. The second function call foo(1) will use the modified list [0] as the default value of x and append 1 to it, resulting in [0, 1]. The third function call foo(2) will use the modified list [0, 1] as the default value of x and append 2 to it, resulting in [0, 1, 2].

    Therefore, the output of the given code will be [0] [0, 1] [0, 1, 2].

    Rate this question:

  • 48. 

    Which of these definitions correctly describes a module?

    • A.

       Denoted by triple quotes for providing the specification of certain program elements

    • B.

      Design and implementation of specific functionality to be incorporated into a program

    • C.

      Defines the specification of how it is to be used

    • D.

      Any program that reuses code

    Correct Answer
    B. Design and implementation of specific functionality to be incorporated into a program
    Explanation
    A module is a unit of code that is designed and implemented to provide specific functionality that can be incorporated into a program. It is not just a specification or a way of using code, but rather the actual implementation of a specific functionality that can be reused in different programs.

    Rate this question:

  • 49. 

    What will be the output of the following Python code? #mod1 def change(a):     b=[x*2 for x in a]     print(b) #mod2 def change(a):     b=[x*x for x in a]     print(b) from mod1 import change from mod2 import change #main s=[1,2,3] change(s)

    • A.

       [2,4,6]

    • B.

      [1,4,9]

    • C.

      [2,4,6] [1,4,9]

    • D.

      There is a name clash

    Correct Answer
    D. There is a name clash
    Explanation
    The output of the code is "There is a name clash" because there are two functions with the same name "change" imported from different modules, mod1 and mod2. When the code tries to call the function "change(s)", it is ambiguous which function should be executed. This results in a name clash error.

    Rate this question:

  • 50. 

      _____ represents an entity in the real world with its identity and behaviour.

    • A.

      A method

    • B.

      An object

    • C.

      A class

    • D.

      An operator

    Correct Answer
    B. An object
    Explanation
    An object represents an entity in the real world with its identity and behavior. Objects are instances of classes and they encapsulate data and methods. They have a unique identity and can perform actions or have actions performed on them. Objects allow for the modeling of real-world entities in a program, enabling interaction and manipulation of data and behavior associated with that entity.

    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 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 08, 2019
    Quiz Created by
    Vaibhav99aggarwa

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.