OA Exams

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

Question 01

What is the output of print(5 // 2) in Python?

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

Correct Answer: a) 2

Explanation: The // operator performs floor division, which returns the largest integer less than or equal to the result of the division.

Question 02

How do you convert a string to a list of characters in Python?

a) str.split()
b) list(str)
c) str.toList()
d) str.split(”)

Correct Answer: b) list(str)

Explanation: The list() function converts a string into a list of characters.

Question 03

What is the purpose of the pass statement in Python?

a) Terminates a loop
b) Skips an iteration in a loop
c) Does nothing and acts as a placeholder
d) Returns a value from a function

Correct Answer: c) Does nothing and acts as a placeholder

Explanation: The pass statement is used as a placeholder where code is syntactically required but not yet implemented.

Question 04

Which function is used to create a dictionary from two lists in Python?

a) zip()
b) dict()
c) map()
d) enumerate()

Correct Answer: b) dict()

Explanation: The dict() function can be used in conjunction with zip() to create a dictionary from two lists (keys and values).

Question 05

How do you declare a multi-line string in Python?

a) ”’ or “””
b) Single quotes
c) Double quotes
d) Triple single quotes only

Correct Answer: a) ''' or """

Explanation: Triple quotes, either ''' or """, are used to create multi-line strings in Python.

Question 06

What does print(10 % 3) return?

a) 1
b) 3
c) 10
d) 0

Correct Answer: a) 1

Explanation: The % operator returns the remainder of the division, so 10 % 3 equals 1.

Question 07

Which of the following is a valid Python variable name?

a) 1var
b) var_name
c) var-name
d) var name

Correct Answer: b) var_name

Explanation: Variable names in Python cannot start with a number and must not contain spaces or hyphens.

Question 08

How do you add an element to the beginning of a list?

a) list.append()
b) list.insert(0, value)
c) list.add(0, value)
d) list[0] = value

Correct Answer: b) list.insert(0, value)

Explanation: The insert() method inserts an element at a specified position, and 0 refers to the first position in the list.

Question 09

Which method is used to remove and return the last element from a list?

a) pop()
b) remove()
c) delete()
d) clear()

Correct Answer: a) pop()

Explanation: The pop() method removes and returns the last element of a list.

Question 10

What is the output of len([1, 2, [3, 4], 5])?

a) 3
b) 4
c) 5
d) 6

Correct Answer: b) 4

Explanation: The len() function counts the top-level elements, and [3, 4] is considered one element.

Question 11

How do you concatenate two tuples in Python?

a) tuple1.append(tuple2)
b) tuple1 + tuple2
c) tuple1.concat(tuple2)
d) tuple1.extend(tuple2)

Correct Answer: b) tuple1 + tuple2

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

Question 12

What does list[::-1] do?

a) Reverses the list
b) Removes elements from the list
c) Slices every second element from the list
d) Returns a shallow copy of the list

Correct Answer: a) Reverses the list

Explanation: The slice notation [::-1] is used to reverse a list.

Question 13

How do you declare a set in Python?

a) {}
b) set[]
c) []
d) set()

Correct Answer: d) set()

Explanation: An empty set is declared using set() because {} is used to declare an empty dictionary.

Question 14

 Which method removes all elements from a set?

a) pop()
b) clear()
c) discard()
d) remove()

Correct Answer: b) clear()

Explanation: The clear() method removes all elements from a set, leaving it empty.

Question 15

What is the output of print(3 == 3.0)?

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

Correct Answer: a) True

Explanation: In Python, == compares values, and 3 is considered equal to 3.0 since their numeric values are the same.

Question 16

 How do you convert a list to a set in Python?

a) set(list)
b) toSet()
c) set.convert(list)
d) list.to_set()

Correct Answer: a) set(list)

Explanation: The set() function converts a list into a set, removing any duplicates in the process.

Question 17

Which of the following is immutable in Python?

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

Correct Answer: c) Tuple

Explanation: A tuple is immutable, meaning that once it is created, its elements cannot be changed.

Question 18

What is the purpose of the lambda keyword in Python?

a) To define a loop
b) To create anonymous functions
c) To import modules
d) To create classes

Correct Answer: b) To create anonymous functions

Explanation: The lambda keyword is used to create small anonymous functions in Python.

Question 19

What does the isinstance() function check?

a) If two variables have the same value
b) If an object belongs to a specified class or type
c) If an object is callable
d) If an object is iterable

Correct Answer: b) If an object belongs to a specified class or type

Explanation: The isinstance() function checks if an object is an instance or subclass of a class or type.

Question 20

What is the output of print(‘python’.capitalize())?

a) Python
b) python
c) PYTHON
d) PytHon

Correct Answer: a) Python

Explanation: The capitalize() method converts the first character of a string to uppercase and the rest to lowercase.

Complete the Captcha to view next question set.

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