OA Exams

  • web.groovymark@gmail.com
  • November 29, 2024

Question 41

What is the output of print(bool(0))?

a) True
b) False
c) None
d) Error

Correct Answer: b) False

Explanation: In Python, 0 evaluates to False in a Boolean context.

Question 42

How do you check if a set is a subset of another set in Python?

a) set.is_subset()
b) set <= other_set
c) set.contains(other_set)
d) set.in(other_set)

Correct Answer: b) set <= other_set

Explanation: The <= operator checks if one set is a subset of another.

Question 43

Which method is used to remove an element from a set in Python?

a) remove()
b) delete()
c) discard()
d) Both a and c

Correct Answer: d) Both a and c

Explanation: The remove() and discard() methods both remove an element from a set, but discard() does not raise an error if the element is not found.

Question 44

What does the any() function do in Python?

a) Returns True if all elements in an iterable are true
b) Returns True if any element in an iterable is true
c) Returns False if all elements in an iterable are false
d) Returns False if any element in an iterable is false

Correct Answer: b) Returns True if any element in an iterable is true

Explanation: The any() function returns True if at least one element of the iterable is true.

Question 45

 What will be the result of print({1, 2, 3} & {2, 3, 4})?

a) {2, 3}
b) {1, 2, 3, 4}
c) {}
d) Error

Correct Answer: a) {2, 3}

Explanation: The & operator returns the intersection of two sets.

Question 46

Which of the following can be used as a dictionary key in Python?

a) List
b) Tuple
c) Set
d) Dictionary

Correct Answer: b) Tuple

Explanation: Dictionary keys must be immutable types, and tuples are immutable, while lists, sets, and dictionaries are mutable.

Question 47

 What is the result of max([10, 20, 30])?

a) 10
b) 20
c) 30
d) Error

Correct Answer: c) 30

Explanation: The max() function returns the largest element from a list.

Question 48

How do you read a file line by line in Python?

a) file.readlines()
b) file.read()
c) file.readline()
d) for line in file:

Correct Answer: d) for line in file:

Explanation: Using a for loop allows you to read a file line by line efficiently.

Question 49

What is the result of print(2 ** 3 ** 2)?

a) 64
b) 512
c) 128
d) 256

Correct Answer: b) 512

Explanation: Exponentiation is evaluated from right to left, so 3 ** 2 is 9, and 2 ** 9 equals 512.

Question 50

What does the strip() method do in Python?

a) Removes leading whitespace
b) Removes trailing whitespace
c) Removes both leading and trailing whitespace
d) Removes all whitespace

Correct Answer: c) Removes both leading and trailing whitespace

Explanation: The strip() method removes whitespace from both the beginning and end of a string.

Complete the Captcha to view next question set.

Prev Post
WGU D335 Practice Exam Questions – Set 5 – Part 2
Next Post
WGU D336 Practice Exam Questions – Set 1 – Part 1