OA Exams

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

Question 21

What method would you use to add an element to the end of a list in Python?

a) append()
b) insert()
c) remove()
d) pop()

Correct Answer: a) append()

Explanation: The append() method adds an element to the end of a list.

Question 22

What is the correct syntax to import the math module in Python?

a) import Math
b) import math()
c) from math import *
d) import math

Correct Answer: d) import math

Explanation: The correct syntax to import the math module is import math.

Question 23

What does the abs() function return?

a) The average of a list of numbers
b) The largest number in a list
c) The absolute value of a number
d) The sum of two numbers

Correct Answer: c) The absolute value of a number

Explanation: The abs() function returns the absolute (non-negative) value of a given number.

Question 24

Which Python data type is used to store key-value pairs?

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

Correct Answer: d) Dictionary

Explanation: A dictionary is a mutable container in Python that stores key-value pairs.

Question 25

How can you remove an element from a list in Python?

a) pop()
b) insert()
c) append()
d) find()

Correct Answer: a) pop()

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

Question 26

 Which of the following is a valid Python variable name?

a) 3value
b) _var_name
c) if
d) var-name

Correct Answer: b) _var_name

Explanation: A valid Python variable name starts with a letter or underscore and contains letters, digits, or underscores.

Question 27

What does x = [1, 2, 3] represent in Python?

a) A tuple
b) A list
c) A set
d) A dictionary

Correct Answer: b) A list

Explanation: A list in Python is created using square brackets, such as [1, 2, 3].

Question 28

Which operator is used for floor division in Python?

a) /
b) //
c) %
d) **

Correct Answer: b) //

Explanation: The // operator performs floor division, which rounds the result down to the nearest whole number.

Question 29

Which method is used to reverse a list in Python?

a) reverse()
b) append()
c) sort()
d) remove()

Correct Answer: a) reverse()

Explanation: The reverse() method reverses the order of the elements in a list.

Question 30

What does the random.randint() function do?

a) Generates a random float number
b) Returns a random integer between a specified range
c) Sorts a list randomly
d) Repeats a block of code

Correct Answer: b) Returns a random integer between a specified range

Explanation: The random.randint() function generates a random integer within a specified range.

Question 31

Which function can be used to generate a random float number between 0 and 1 in Python?

a) randint()
b) uniform()
c) random()
d) choice()

Correct Answer: c) random()

Explanation: The random() function generates a random float number between 0.0 and 1.0.

Question 32

What is the default value returned by a Python function if no return statement is specified?

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

Correct Answer: c) None

Explanation: If a Python function does not have a return statement, it returns None by default.

Question 33

How do you create a tuple in Python?

a) Using curly braces {}
b) Using parentheses ()
c) Using square brackets []
d) Using angle brackets <>

Correct Answer: b) Using parentheses ()

Explanation: A tuple is created by placing values inside parentheses, such as (1, 2, 3).

Question 34

Which method is used to find the position of a character in a string?

a) find()
b) count()
c) index()
d) position()

Correct Answer: a) find()

Explanation: The find() method returns the index of the first occurrence of a substring in a string.

Question 35

What is the output of the following code: print(2 ** 3)?

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

Correct Answer: c) 8

Explanation: The ** operator raises a number to a power, so 2 ** 3 equals 8.

Question 36

Which function returns the type of an object in Python?

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

Correct Answer: a) type()

Explanation: The type() function returns the type of an object, such as int, float, or str.

Question 37

Which method removes whitespace from the beginning and end of a string in Python?

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

Correct Answer: a) strip()

Explanation: The strip() method removes leading and trailing whitespace from a string.

Question 38

What is the purpose of the continue statement in a loop?

a) To exit the loop
b) To skip the current iteration and continue with the next
c) To restart the loop
d) To stop the program

Correct Answer: b) To skip the current iteration and continue with the next

Explanation: The continue statement causes the loop to skip the current iteration and move on to the next one.

Question 39

What type of data does the input() function return?

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

Correct Answer: c) String

Explanation: The input() function always returns user input as a string.

Question 40

What is a comment in Python denoted by?

a) #
b) @
c) //
d) /* */

Correct Answer: a) #

Explanation: A comment in Python is denoted by the # symbol.

Complete the Captcha to view next question set.

Tags

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