OA Exams

  • web.groovymark@gmail.com
  • December 8, 2024

Question 41

What does this Python code return?

print(“Python”.islower())

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

Correct Answer: b) False

Explanation: The islower() method checks whether all letters in the string are lowercase. "Python" contains uppercase letters, so it returns False.

Question 42

What is the result of this Python code?

x = 10

y = 20

print(x > y)

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

Correct Answer: b) False

Explanation: Since x is less than y, the expression x > y evaluates to `

Question 43

What does this Python code return?

print(“Hello World!”.replace(“World”, “Python”))

a) Hello Python!
b) Hello World!
c) Hello
d) Error

Correct Answer: a) Hello Python!

Explanation: The replace() method replaces occurrences of a substring with another substring. Here, "World" is replaced with "Python".

Question 44

What will be the result of this Python code?

x = [1, 2, 3, 4, 5]

print(x[1:4])

a) [1, 2, 3, 4]
b) [2, 3, 4]
c) [3, 4, 5]
d) Error

Correct Answer: b) [2, 3, 4]

Explanation: The slice [1:4] returns the elements from index 1 to 3 (index 4 is excluded).

Question 45

What does this Python code return?

print(type((1,)))

a) <class ‘tuple’>
b) <class ‘list’>
c) <class ‘int’>
d) Error

Correct Answer: a) <class 'tuple'>

Explanation: A tuple with a single element requires a trailing comma, as in (1,). Without the comma, it would be considered an integer.

Question 46

What will this Python code output?

x = “12345”

print(x[::-1])

a) 54321
b) 12345
c) None
d) Error

Correct Answer: a) 54321

Explanation: The slice [::-1] reverses the string by stepping through it backwards.

Question 47

What is the result of this Python code?

x = [1, 2, 3]

y = [4, 5]

x.extend(y)

print(x)

a) [1, 2, 3, 4, 5]
b) [4, 5]
c) [1, 2, 3]
d) Error

Correct Answer: a) [1, 2, 3, 4, 5]

Explanation: The extend() method adds all elements from the iterable y to the end of the list x.

Question 48

What will this Python code output?

x = 5

if x != 5:

    print(“Not Five”)

else:

    print(“Five”)

a) Not Five
b) Five
c) Error
d) None

Correct Answer: b) Five

Explanation: The condition x != 5 is False because x is equal to 5, so the else block is executed, printing "Five".

Question 49

What does this Python code return?

print(“abc”.isalpha())

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

Correct Answer: a) True

Explanation: The isalpha() method returns True if all characters in the string are alphabetic. "abc" contains only alphabetic characters, so it returns True.

Question 50

 What will this Python code output?

x = {“a”: 1, “b”: 2, “c”: 3}

print(len(x))

a) 2
b) 3
c) 1
d) Error

Correct Answer: b) 3

Explanation: The len() function returns the number of key-value pairs in the dictionary, which is 3 in this case.

Complete the Captcha to view next question set.

Tags

Prev Post
WGU D522 Practice Exam Questions – Set 3 – Part 2
Next Post
WGU D522 Practice Exam Questions – Set 4 – Part 1