Unitechtransfer-german Centre For Automation And Robotics,Germany.

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 UniTechTransfer
U
UniTechTransfer
Community Contributor
Quizzes Created: 1 | Total Attempts: 557
Questions: 25 | Attempts: 557

SettingsSettingsSettings
German Quizzes & Trivia

Questions and Answers
  • 1. 

    Which is the correct operator for power(x^y)?

    • A.

      X^y

    • B.

      X**y

    • C.

      X^^y

    • D.

      None of the mentioned

    Correct Answer
    B. X**y
    Explanation
    The correct operator for power(x^y) is X**y. This is the exponentiation operator in many programming languages, including Python. It raises the value of X to the power of y. The caret symbol (^) is not commonly used for exponentiation in programming languages, and X^^y is not a valid operator. Therefore, the correct answer is X**y.

    Rate this question:

  • 2. 

    What is the output of the following? sentence = 'horses are fast' regex = re.compile('(?P\w+) (?P\w+) (?P\w+)') matched = re.search(regex, sentence) print(matched.groups())

    • A.

      {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}

    • B.

      (‘horses’, ‘are’, ‘fast’)

    • C.

      ‘horses are fast’

    • D.

      ‘are’

    Correct Answer
    B. (‘horses’, ‘are’, ‘fast’)
    Explanation
    The given code uses regular expressions to search for a pattern in the sentence "horses are fast". The pattern is defined as three groups of words separated by spaces. The matched.groups() method returns a tuple containing the matched groups, which in this case are ('horses', 'are', 'fast').

    Rate this question:

  • 3. 

    Which of the following cannot be a variable?

    • A.

      __init__

    • B.

      it

    • C.

      In

    • D.

      On

    Correct Answer
    C. In
    Explanation
    The word "in" cannot be a variable because it is a reserved keyword in Python. Reserved keywords are words that have a special meaning and purpose in the programming language, and they cannot be used as variable names. In Python, "in" is used as a keyword to check if a value is present in a sequence, such as a list or a string. Therefore, it cannot be used as a variable name.

    Rate this question:

  • 4. 

    What is the output of the following? x = "abcdef" i = "a" while i in x[1:]: print(i, end = " ")

    • A.

      A a a a a a

    • B.

      A

    • C.

      No output

    • D.

      Error

    Correct Answer
    C. No output
    Explanation
    The output of the given code is "no output" because the while loop condition checks if the variable "i" is in the string "x[1:]", which is "bcdef". Since "i" is not present in "bcdef", the loop does not execute and no output is printed.

    Rate this question:

  • 5. 

    What is the output of the following? for i in '': print (i)

    • A.

      None

    • B.

      (nothing is printed)

    • C.

      Error

    • D.

      None of the mentioned

    Correct Answer
    B. (nothing is printed)
    Explanation
    The given code uses a for loop to iterate over an empty string. Since there are no characters in the string, the loop does not execute and nothing is printed. This is why the output is "nothing is printed".

    Rate this question:

  • 6. 

    What is the output of the following code ?
    1. >>>example = "helle"
    2. >>>example.rfind("e")

    • A.

      4

    • B.

      3

    • C.

      1

    • D.

      -1

    Correct Answer
    A. 4
    Explanation
    The output of the code is 4. The rfind() function is used to find the last occurrence of a specified substring within a string. In this case, the last occurrence of the letter "e" in the string "helle" is at index 4.

    Rate this question:

  • 7. 

    What is the output when following code is executed ?
    1. >>>print("D", end = ' ')
    2. >>>print("C", end = ' ')
    3. >>>print("B", end = ' ')
    4. >>>print("A", end = ' ')

    • A.

      DCBA

    • B.

      A, B, C, D

    • C.

      D C B A

    • D.

      A, B, C, D will be displayed on four lines

    Correct Answer
    C. D C B A
    Explanation
    The code will print the letters "D C B A" in that order, with each letter separated by a space. The "end = ' '" argument in the print function specifies that a space should be used as the separator between the printed items. Therefore, the output will be "D C B A".

    Rate this question:

  • 8. 

    What is the output of the following?print("abcdef".center(10, '12'))

    • A.

      12abcdef12

    • B.

      Abcdef1212

    • C.

      1212abcdef

    • D.

      Error

    Correct Answer
    D. Error
    Explanation
    The output of the given code will be "error". The center() method is used to center-align a string within a specified width. In this case, the specified width is 10. However, the second argument provided for center() should be a single character, not a string. In the given code, "12" is provided as the second argument, which is a string of two characters. Hence, an error will occur.

    Rate this question:

  • 9. 

    What is the output of the following?print("abcdef".find("cd") == "cd" in "abcdef")

    • A.

      True

    • B.

      False

    • C.

      Error

    • D.

      None of the mentioned.

    Correct Answer
    B. False
    Explanation
    The code is comparing the result of the find() method with the expression "cd" in "abcdef". The find() method returns the index of the first occurrence of the substring "cd" in the string "abcdef". In this case, "cd" is found at index 2. However, the expression "cd" in "abcdef" returns a boolean value indicating whether the substring "cd" is present in the string "abcdef". Since "cd" is present in "abcdef", the expression evaluates to True. Therefore, the correct answer should be True, not False.

    Rate this question:

  • 10. 

    What is the output of the following?print('my_string'.isidentifier())

    • A.

      True

    • B.

      False

    • C.

      None

    • D.

      Error

    Correct Answer
    A. True
    Explanation
    The output of the given code is True. The isidentifier() method is used to check if a string is a valid identifier in Python. In this case, the string 'my_string' is a valid identifier as it consists of only alphanumeric characters and underscores, and does not start with a number. Therefore, the isidentifier() method returns True.

    Rate this question:

  • 11. 

    What is the output of the following?print('1.1'.isnumeric())

    • A.

      True

    • B.

      False

    • C.

      None

    • D.

      Error

    Correct Answer
    B. False
    Explanation
    The isnumeric() method in Python returns True if all characters in a string are numeric, otherwise it returns False. In this case, the string '1.1' contains a decimal point, which is not considered numeric. Therefore, the output of the code is False.

    Rate this question:

  • 12. 

    To shuffle the list(say list1) what function do we use ?

    • A.

      list1.shuffle()

    • B.

      Shuffle(list1)

    • C.

      Random.shuffle(list1)

    • D.

      Random.shuffleList(list1)

    Correct Answer
    C. Random.shuffle(list1)
    Explanation
    The correct answer is random.shuffle(list1). This function is used to shuffle the elements in a list randomly. It takes a list as an argument and rearranges its elements in a random order. By using this function, the original order of the list is changed, providing a randomized version of the list.

    Rate this question:

  • 13. 

    What is the output when following code is executed ?
    1. >>>"Welcome to Python".split()

    • A.

      [“Welcome”, “to”, “Python”]

    • B.

      (“Welcome”, “to”, “Python”)

    • C.

      {“Welcome”, “to”, “Python”}

    • D.

      “Welcome”, “to”, “Python”

    Correct Answer
    A. [“Welcome”, “to”, “Python”]
    Explanation
    The given code is using the split() method on the string "Welcome to Python". The split() method splits a string into a list of substrings based on a specified delimiter, which is by default a space. Therefore, the output of the code will be a list ["Welcome", "to", "Python"], as each word is separated by a space.

    Rate this question:

  • 14. 

    What will be the output?
    1. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
    2.  
    3. v = values[0][0]
    4. for row in range(0, len(values)):
    5. for column in range(0, len(values[row])):
    6. if v < values[row][column]:
    7. v = values[row][column]
    8.  
    9. print(v)

    • A.

      3

    • B.

      5

    • C.

      6

    • D.

      33

    Correct Answer
    D. 33
    Explanation
    The code initializes the variable v with the first element of the first sublist in the values list, which is 3. Then, it iterates over each element in the values list using nested for loops. If an element is greater than v, v is updated with that element. The last element in the values list is 33, which is greater than all the other elements. Therefore, the final value of v is 33, and that is the output.

    Rate this question:

  • 15. 

    What will be the output?
    1. d1 = {"john":40, "peter":45}
    2. d2 = {"john":466, "peter":45}
    3. d1 > d2

    • A.

      True

    • B.

      False

    • C.

      Error

    • D.

      None

    Correct Answer
    C. Error
    Explanation
    The given code will result in an error. This is because the comparison operator ">" cannot be used to compare two dictionaries directly.

    Rate this question:

  • 16. 

    What will be the output?
    1. >>>t=(1,2,4,3)
    2. >>>t[1:-1]

    • A.

      (1, 2)

    • B.

      (1, 2, 4)

    • C.

      (2, 4)

    • D.

      (2, 4, 3)

    Correct Answer
    C. (2, 4)
    Explanation
    The output will be (2, 4) because when we use the slice notation [1:-1], it selects elements from index 1 to the second-to-last element of the tuple. In this case, the tuple t has elements (1, 2, 4, 3), so the slice [1:-1] will select elements 2 and 4, resulting in the tuple (2, 4).

    Rate this question:

  • 17. 

    To open a file c:\scores.txt for writing, we use

    • A.

      Outfile = open(“c:\scores.txt”, “w”)

    • B.

      Outfile = open(“c:\\scores.txt”, “w”)

    • C.

      Outfile = open(file = “c:\scores.txt”, “w”)

    • D.

      Outfile = open(file = “c:\\scores.txt”, “w”)

    Correct Answer
    B. Outfile = open(“c:\\scores.txt”, “w”)
    Explanation
    The correct answer is `outfile = open("c:\\scores.txt", "w")`. This is because when specifying a file path in Python, backslashes (\) are used to escape special characters. Since the backslash itself is a special character, it needs to be escaped by using another backslash. Therefore, in order to specify the file path "c:\scores.txt", we need to use "c:\\scores.txt". The "w" argument in the `open()` function is used to indicate that the file should be opened in write mode.

    Rate this question:

  • 18. 

    What is the output of this program?
    1. fo = open("foo.txt", "rw+")
    2. print "Name of the file: ", fo.name
    3.  
    4. # Assuming file has following 5 lines
    5. # This is 1st line
    6. # This is 2nd line
    7. # This is 3rd line
    8. # This is 4th line
    9. # This is 5th line
    10.  
    11. for index in range(5):
    12. line = fo.next()
    13. print "Line No %d - %s" % (index, line)
    14.  
    15. # Close opend file
    16. fo.close()

    • A.

      Compilation Error

    • B.

      Syntax Error

    • C.

      Displays Output

    • D.

      None of the mentioned

    Correct Answer
    C. Displays Output
    Explanation
    The program opens a file named "foo.txt" in read-write mode and assigns it to the variable "fo". It then prints the name of the file, which is "foo.txt".

    Next, it enters a loop that iterates 5 times. In each iteration, it reads a line from the file using the "next()" method of the file object and assigns it to the variable "line". It then prints the line number and the content of the line.

    Finally, it closes the file.

    Since the program does not contain any syntax errors and the file "foo.txt" exists, it will display the output as expected.

    Rate this question:

  • 19. 

    What is the output of this program?
    1. import sys
    2.  
    3. sys.stdout.write(' Hello\n')
    4. sys.stdout.write('Python\n')

    • A.

      Compilation Error

    • B.

      Runtime Error

    • C.

      Hello Python

    • D.

      Hello Python

    Correct Answer
    D. Hello Python
    Explanation
    The program uses the sys.stdout.write() function to print two strings: "Hello" and "Python". The write() function does not automatically add a newline character, so the two strings are printed on the same line. Therefore, the output of the program will be "Hello Python".

    Rate this question:

  • 20. 

    What is the use of “w” in file handling?

    • A.

      Read

    • B.

      Write

    • C.

      Append

    • D.

      None of the above

    Correct Answer
    B. Write
    Explanation
    The use of "w" in file handling is to open a file in write mode. This allows the program to write data to the file, overwriting any existing content. By using "w", the program can create a new file if it doesn't exist or truncate the file if it does exist. This mode is commonly used when the program needs to update or modify the content of a file.

    Rate this question:

  • 21. 

    What is the output of the below program?
    1. def printMax(a, b):
    2. if a > b:
    3. print(a, 'is maximum')
    4. elseif a == b:
    5. print(a, 'is equal to', b)
    6. else:
    7. print(b, 'is maximum')
    8. printMax(3, 4)

    • A.

      3

    • B.

      4

    • C.

      4 is maximum

    • D.

      None of the mentioned.

    Correct Answer
    C. 4 is maximum
    Explanation
    The program defines a function called printMax that takes two arguments, a and b. It then uses an if-else statement to compare the values of a and b. If a is greater than b, it prints "a is maximum". If a is equal to b, it prints "a is equal to b". Otherwise, it prints "b is maximum". In this case, the values of a and b are 3 and 4 respectively, so the output will be "4 is maximum".

    Rate this question:

  • 22. 

    What is called when a function is defined inside a class?

    • A.

      Module

    • B.

      Class

    • C.

      Another Function

    • D.

      Method

    Correct Answer
    D. Method
    Explanation
    A function defined inside a class is called a method. In object-oriented programming, a method is a behavior or action that an object can perform. It is associated with a specific class and can access the data and other methods within that class. Methods are used to define the behavior of objects and to perform specific tasks or operations.

    Rate this question:

  • 23. 

    What is the output of below program?
    1. def f(x, y, z): return x + y + z
    2.  
    3. f(2, 30, 400)

    • A.

      432

    • B.

      24000

    • C.

      430

    • D.

      None of the mentioned

    Correct Answer
    A. 432
    Explanation
    The program defines a function f that takes three arguments x, y, and z and returns their sum. Then, the function is called with the arguments 2, 30, and 400. So, the output of the program is the sum of these three numbers, which is 432.

    Rate this question:

  • 24. 

    Which module in Python supports regular expressions?

    • A.

      Re

    • B.

      Regex

    • C.

      Pyregex

    • D.

      None of the mentioned

    Correct Answer
    A. Re
    Explanation
    The correct answer is "re". The "re" module in Python supports regular expressions. Regular expressions are used for pattern matching and manipulating strings. The "re" module provides functions and methods for working with regular expressions in Python.

    Rate this question:

  • 25. 

    Which of the following creates a pattern object?

    • A.

      re.create(str)

    • B.

      re.regex(str)

    • C.

      Re.compile(str)

    • D.

      Re.assemble(str)

    Correct Answer
    C. Re.compile(str)
    Explanation
    The correct answer is "re.compile(str)". The "re.compile()" function in Python's "re" module is used to create a pattern object. This pattern object can then be used to perform various operations like searching, matching, and replacing strings using regular expressions.

    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
  • Oct 11, 2016
    Quiz Created by
    UniTechTransfer
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.