OA Exams

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

Question 21

What is the result of round(4.67)?

a) 4
b) 5
c) 4.5
d) 4.7

Correct Answer: b) 5

Explanation: The round() function rounds a number to the nearest integer, so 4.67 is rounded up to 5.

Question 22

How do you reverse a string in Python?

a) reverse()
b) reversed()
c) [::-1]
d) flip()

Correct Answer: c) [::-1]

Explanation: The slicing syntax [::-1] reverses the string.

Question 23

Which of the following is a mutable data type in Python?

a) Tuple
b) List
c) String
d) Integer

Correct Answer: b) List

Explanation: Lists are mutable, meaning their elements can be changed after creation, while tuples, strings, and integers are immutable.

Question 24

 What does the update() method do in Python?

a) Updates a list by adding new elements
b) Updates a dictionary by adding or modifying key-value pairs
c) Updates a tuple by modifying its elements
d) Updates a set by removing duplicate elements

Correct Answer: b) Updates a dictionary by adding or modifying key-value pairs

Explanation: The update() method in dictionaries adds new key-value pairs or updates existing ones.

Question 25

How do you remove leading and trailing whitespace from a string in Python?

a) strip()
b) remove()
c) trim()
d) clear()

Correct Answer: a) strip()

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

Question 26

What is the result of 2 ** 3 in Python?

a) 6
b) 8
c) 9
d) 12

Correct Answer: b) 8

Explanation: The ** operator is used for exponentiation, so 2 ** 3 equals 2 * 2 * 2, which is 8.

Question 27

 Which function is used to find the largest number in a list?

a) max()
b) min()
c) sum()
d) largest()

Correct Answer: a) max()

Explanation: The max() function returns the largest value in a list or other iterable.

Question 28

What is a key characteristic of a set in Python?

a) It is ordered
b) It allows duplicate elements
c) It is mutable
d) It can have multiple data types

Correct Answer: c) It is mutable

Explanation: A set is mutable, meaning its elements can be added or removed, but it does not allow duplicate elements.

Question 29

How do you find the data type of a variable in Python?

a) type()
b) len()
c) str()
d) id()

Correct Answer: a) type()

Explanation: The type() function returns the data type of the given variable.

Question 30

What is the output of print(list(range(3)))?

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

Correct Answer: b) [0, 1, 2]

Explanation: The range() function generates numbers starting from 0, and range(3) returns [0, 1, 2].

Question 31

Which method returns the number of elements in a list?

a) size()
b) count()
c) length()
d) len()

Correct Answer: d) len()

Explanation: The len() function returns the number of elements in a list.

Question 32

What does the continue statement do in a loop?

a) Exits the loop
b) Skips the current iteration and continues with the next one
c) Terminates the program
d) Restarts the loop

Correct Answer: b) Skips the current iteration and continues with the next one

Explanation: The continue statement skips the remaining code in the current iteration and proceeds to the next iteration of the loop.

Question 33

 How do you check if a key exists in a dictionary?

a) if key in dict:
b) if dict.hasKey(key):
c) if dict.contains(key):
d) if key == dict:

Correct Answer: a) if key in dict:

Explanation: The in operator checks if a key exists in a dictionary.

Question 34

34. Which function converts a number into a floating-point number?

a) int()
b) str()
c) float()
d) list()

Correct Answer: c) float()

Explanation: The float() function converts a number into a floating-point number.

Question 35

How do you declare a global variable inside a function in Python?

a) declare global var_name
b) global var_name
c) var_name global
d) declare var_name

Correct Answer: b) global var_name

Explanation: The global keyword is used to declare a global variable inside a function.

Question 36

What does the startswith() method do?

a) Checks if a string ends with a specified value
b) Checks if a string starts with a specified value
c) Checks if a string contains a specified value
d) Replaces characters in a string

Correct Answer: b) Checks if a string starts with a specified value

Explanation: The startswith() method returns True if the string starts with the specified prefix.

Question 37

What is the output of print(“Hello ” + “World”)?

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

Correct Answer: b) Hello World

Explanation: The + operator concatenates the two strings with no additional spaces, so the output is "Hello World".

Question 38

 How do you sort a list in ascending order?

a) list.sort()
b) sorted(list)
c) list.sorted()
d) Both a and b

Correct Answer: d) Both a and b

Explanation: You can use either list.sort() or sorted(list) to sort a list in ascending order. The former modifies the list in place, while the latter returns a new sorted list.

Question 39

What will print(bool(“”)) return?

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

Correct Answer: b) False

Explanation: An empty string is considered False in a Boolean context in Python.

Question 40

Which keyword is used to handle exceptions in Python?

a) throw
b) catch
c) try
d) except

Correct Answer: c) try

Explanation: The try keyword is used to handle exceptions in Python. It is typically followed by except.

Complete the Captcha to view next question set.

Tags

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