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 will print(10 // 3) output in Python?

a) 3
b) 3.33
c) 3.0
d) 4

Correct Answer: a) 3

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

Question 02

Which of the following creates an empty list in Python?

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

Correct Answer: b) list = []

Explanation: An empty list is created using square brackets [].

Question 03

What is the output of print(‘hello’.upper()) in Python?

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

Correct Answer: b) HELLO

Explanation: The upper() method converts all characters of a string to uppercase.

Question 04

Which method is used to combine the contents of two dictionaries in Python?

a) dict.add()
b) dict.update()
c) dict.concat()
d) dict.join()

Correct Answer: b) dict.update()

Explanation: The update() method adds key-value pairs from one dictionary to another.

Question 05

 What will print([1, 2, 3] + [4, 5]) output in Python?

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

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

Explanation: Using + concatenates two lists into a single list.

Question 06

What is the correct syntax for defining a function in Python?

a) def function_name:
b) function function_name:
c) def function_name():
d) func function_name():

Correct Answer: c) def function_name():

Explanation: Functions in Python are defined using the def keyword followed by the function name and parentheses ().

Question 07

How do you add a single element to a set in Python?

a) set.add()
b) set.append()
c) set.insert()
d) set.extend()

Correct Answer: a) set.add()

Explanation: The add() method adds a single element to a set.

Question 08

What is the correct way to check if an element is in a list in Python?

a) element in list
b) list.has(element)
c) element.contains(list)
d) list.exists(element)

Correct Answer: a) element in list

Explanation: The in keyword checks if an element exists in a list.

Question 09

Which of the following is a tuple in Python?

a) {1, 2, 3}
b) [1, 2, 3]
c) (1, 2, 3)
d) {{1, 2, 3}}

Correct Answer: c) (1, 2, 3)

Explanation: A tuple is defined using parentheses ().

Question 10

What does the clear() method do for a list in Python?

a) Removes one element from the list
b) Deletes the list from memory
c) Removes all elements from the list
d) Reverses the list

Correct Answer: c) Removes all elements from the list

Explanation: The clear() method empties the list by removing all elements.

Question 11

Which method can be used to combine all elements in a list into a single string?

a) concat()
b) join()
c) merge()
d) append()

Correct Answer: b) join()

Explanation: The join() method concatenates the elements of a list into a single string, with a separator between each element.

Question 12

How do you define a multi-line comment in Python?

a) // comment //
b) /* comment */
c) ”’ comment ”’
d) ## comment ##

Correct Answer: c) ''' comment '''

Explanation: Multi-line comments in Python are written using triple quotes '''.

Question 13

What is the output of print(type(42))?

a) int
b) float
c) bool
d) str

Correct Answer: a) int

Explanation: The type() function returns the type of the object, and 42 is an integer.

Question 14

How do you access the first element of a tuple t = (10, 20, 30)?

a) t[0]
b) first()
c) t(0)
d) t[1]

Correct Answer: a) t[0]

Explanation: Tuples are indexed similarly to lists, and the first element has an index of 0.

Question 15

Which operator is used to check if two values are the same object in memory?

a) ==
b) !=
c) is
d) in

Correct Answer: c) is

Explanation: The is operator checks if two variables refer to the same object in memory.

Question 16

What is the output of bool(None) in Python?

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

Correct Answer: b) False

Explanation: None evaluates to False in a Boolean context.

Question 17

 How do you check if a list is empty in Python?

a) if list == None
b) if len(list) == 0
c) if not list
d) Both b and c

Correct Answer: d) Both b and c

Explanation: You can check if a list is empty by using either len(list) == 0 or if not list, which evaluates to True if the list is empty.

Question 18

What is the output of print(“abc” * 3)?

a) abcabcabc
b) abc abc abc
c) abc*3
d) Error

Correct Answer: a) abcabcabc

Explanation: Multiplying a string by an integer repeats the string that many times.

Question 19

Which of the following creates a dictionary in Python?

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

Correct Answer: b) d = {}

Explanation: An empty dictionary is created using curly braces {}.

Question 20

What does the sorted() function do in Python?

a) Sorts a list in place
b) Returns a sorted list
c) Sorts a dictionary by values
d) Sorts elements in reverse

Correct Answer: b) Returns a sorted list

Explanation: The sorted() function returns a new list with elements in sorted order without modifying the original list.

Complete the Captcha to view next question set.

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