OA Exams

  • California, TX 70240
  • Info@gmail.com
  • Office Hours: 8:00 AM – 7:45 PM
  • web.groovymark@gmail.com
  • December 8, 2024

Question 21

What will be the output of this code?

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

print(numbers[-1])

a) 1
b) 5
c) 4
d) Error

Correct Answer: b) 5

Explanation: Negative indexing starts from the end of the list. numbers[-1] accesses the last element, which is 5.

Question 22

What is the output of the following Python code?

x = [1, 2, 3]

y = [1, 2, 3]

print(x is y)

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

Correct Answer: b) False

Explanation: Even though x and y have the same contents, they are different objects in memory. The is operator checks for object identity, not value equality.

Question 23

What does the following code return?

print(2 in [1, 2, 3])

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

Correct Answer: a) True

Explanation: The in keyword checks for membership. Since 2 is an element of the list [1, 2, 3], the result is True.

Question 24

What will this Python code output?

x = “Python”

print(x[2:])

a) P
b) tho
c) thon
d) thonPython

Correct Answer: c) thon

Explanation: The slice [2:] starts from index 2 and goes to the end of the string. In 'Python', index 2 corresponds to 't'.

Question 25

What will this code output?

print(type([1, 2, 3]))

a) <class ‘tuple’>
b) <class ‘list’>
c) <class ‘set’>
d) <class ‘dict’>

Correct Answer: b) <class 'list'>

Explanation: The type() function returns the type of the object. [1, 2, 3] is a list, so the output will be <class 'list'>.

Question 26

Which of the following is a valid Python variable name?

a) 1st_place
b) first-place
c) first_place
d) first place

Correct Answer: c) first_place

Explanation: Python variable names cannot start with a digit, contain spaces, or use hyphens. The name first_place is valid.

Question 27

What does this Python code do?

my_dict = {“name”: “Alice”, “age”: 25}

print(my_dict[“name”])

a) Prints 25
b) Prints Alice
c) Prints name
d) Error

Correct Answer: b) Prints Alice

Explanation: The dictionary my_dict stores values associated with keys. my_dict["name"] accesses the value associated with the key "name", which is "Alice".

Question 28

What is the result of this Python code?

print(“Hello”.lower())

a) HELLO
b) Hello
c) hello
d) Error

Correct Answer: c) hello

Explanation: The lower() method converts all characters in the string to lowercase. "Hello" becomes "hello".

Question 29

What will the following code output?

print(3 * ‘A’)

a) A A A
b) AAA
c) A
d) 3A

Correct Answer: b) AAA

Explanation: The * operator can be used to repeat a string. 'A' * 3 results in the string 'AAA'.

Question 30

What does the following code return?

print(type((1, 2, 3)))

a) <class ‘list’>
b) <class ‘tuple’>
c) <class ‘set’>
d) <class ‘dict’>

Correct Answer: b) <class 'tuple'>

Explanation: The type of (1, 2, 3) is a tuple. The type() function returns <class 'tuple'>.

Question 31

What will be the output of this code?

print(“Python”[::-1])

a) Python
b) nohtyP
c) nohty
d) Error

Correct Answer: b) nohtyP

Explanation: The slice [::-1] reverses the string. The result is the reversed version of "Python", which is "nohtyP".

Question 32

What will this Python code output?

for i in range(3):

    print(i, end=”, “)

a) 0, 1, 2
b) 0, 1, 2,
c) 0 1 2
d) Error

Correct Answer: b) 0, 1, 2,

Explanation: The end=", " argument in the print() function adds a comma and space after each printed value, including the last one.

Question 33

What does this Python code do?

x = [1, 2, 3]

y = x.copy()

y.append(4)

print(x)

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

Correct Answer: a) Prints [1, 2, 3]

Explanation: The copy() method creates a shallow copy of the list x. Changes to y do not affect the original list x.

Question 34

Which operator is used to concatenate strings in Python?

a) +
b) *
c) %
d) &

Correct Answer: a) +

Explanation: The + operator is used to concatenate two strings in Python.

Question 35

What will be the output of this code?

print(10 / 4)

a) 2
b) 2.5
c) 2.0
d) 3

Correct Answer: b) 2.5

Explanation: The / operator performs true division and returns a floating-point number. 10 / 4 equals 2.5.

Question 36

What will this Python code return?

fruits = [“apple”, “banana”, “cherry”]

fruits.insert(1, “orange”)

print(fruits)

a) [“apple”, “orange”, “banana”, “cherry”]
b) [“apple”, “banana”, “cherry”, “orange”]
c) [“orange”, “apple”, “banana”, “cherry”]
d) Error

Correct Answer: a) ["apple", "orange", "banana", "cherry"]

Explanation: The insert() method inserts an element at a specified position in the list. "orange" is inserted at index 1.

Question 37

What will be the result of this Python code?

x = [1, 2, 3]

x.remove(2)

print(x)

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

Correct Answer: b) [1, 3]

Explanation: The remove() method removes the first occurrence of the specified element from the list. In this case, 2 is removed.

Question 38

What does this Python code return?

print(type({1, 2, 3}))

a) <class ‘list’>
b) <class ‘tuple’>
c) <class ‘set’>
d) <class ‘dict’>

Correct Answer: c) <class 'set'>

Explanation: The curly braces {} denote a set in Python. The type() function returns <class 'set'> for {1, 2, 3}.

Question 39

 What is the result of this Python expression?

x = “123”

print(x.isdigit())

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

Correct Answer: a) True

Explanation: The isdigit() method returns True if all characters in the string are digits. "123" contains only digits, so the result is True.

Question 40

What will this Python code return?

print([1, 2, 3] + [4, 5, 6])

a) [1, 2, 3, [4, 5, 6]]
b) [5, 7, 9]
c) [1, 2, 3, 4, 5, 6]
d) [1, 2, 3]

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

Explanation: The + operator concatenates two lists in Python. [1, 2, 3] + [4, 5, 6] results in [1, 2, 3, 4, 5, 6].

Complete the Captcha to view next question set.

Tags

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