What function in Python is used to get input from the user?
Correct answer:
B) input()
Explanation: The input() function is used to get user input as a string.
What function in Python is used to get input from the user?
Correct answer:
B) input()
Explanation: The input() function is used to get user input as a string.
What is a string literal in Python?
Correct answer:
A) Text enclosed in quotes
Explanation: A string literal is text enclosed in single or double quotes, representing text data.
How can you keep multiple print() statements on the same line in Python?
Correct answer:
B) Use end=’ ‘
Explanation: The end=' ' parameter prevents the print() function from moving to the next line
What is the symbol for an exponent operator in Python?
Correct answer:
C) **
Explanation: The ** operator is used to perform exponentiation in Python, such as x ** y .
Which function returns the number of elements in a list or string in Python?
Correct answer:
B) len()
Explanation: The len() function returns the length of a list, string, or other iterable.
What type of loop repeats as long as a specified condition is true in Python?
Correct answer:
B) while loop
Explanation: A while loop repeatedly executes code as long as its condition evaluates to True .
Which function converts a string to an integer in Python?
Correct answer:
A) int()
Explanation: The int() function converts a valid string or float to an integer.
What is a syntax error in Python?
Correct answer:
C) Violation of programming language rules
Explanation: A syntax error occurs when the code does not conform to the syntax rules of the language.
What does \\n represent in Python strings?
Correct answer:
B) Newline
Explanation: \\n is an escape sequence that moves the output to the next line.
What error occurs when a program attempts an impossible operation, such as dividing by zero?
Correct answer:
B) Runtime error
Explanation: A runtime error occurs during program execution when an operation is not possible, like dividing by zero.
What is the purpose of indentation in Python code?
Correct answer:
B) To separate code blocks
Explanation: Python uses indentation to define code blocks, such as those in loops and functions.
What does the float() function do in Python?
Correct answer:
B) Converts an integer to a floating-point number
Explanation: The float() function converts integers or strings to floating-point numbers.
What is the result of 5 // 2 in Python?
Correct answer:
C) 2
Explanation: // is the floor division operator, which returns the largest integer less than or equal to the division result.
Which Python keyword is used to define a function?
Correct answer:
B) def
Explanation: The def keyword is used to define a new function in Python
What does the return statement do in a function?
Correct answer:
C) Returns a value to the caller
Explanation: The return statement exits the function and sends a value back to where the function was called.
What does pass do in Python code?
Correct answer:
C) It is a placeholder that does nothing
Explanation: The pass statement is used when a statement is required syntactically but no action is needed.
Which Python function can round a floating-point number up to the nearest integer?
Correct answer:
A) ceil()
Explanation: The ceil() function from the math module rounds a floating-point number up to the next whole number.
What is a list in Python?
Correct answer:
C) A mutable container with ordered elements
Explanation: A list is a mutable collection in Python, meaning its contents can be modified.
Which operator is used for string concatenation in Python?
Correct answer:
B) +
Explanation: The + operator is used to concatenate two strings in Python.
What does the len() function return when applied to a list?
Correct answer:
C) The number of elements in the list
Explanation: The len() function returns the total number of elements in a list or string.
What method would you use to add an element to the end of a list in Python?
Correct answer:
A) append()
Explanation: The append() method adds an element to the end of a list.
What is the correct syntax to import the math module in Python?
Correct answer:
D) import math
Explanation: The correct syntax to import the math module is import math .
What does the abs() function return?
Correct answer:
C) The absolute value of a number
Explanation: The abs() function returns the absolute (non-negative) value of a given number.
Which Python data type is used to store key-value pairs?
Correct answer:
D) Dictionary
Explanation: A dictionary is a mutable container in Python that stores key-value pairs.
How can you remove an element from a list in Python?
Correct answer:
A) pop()
Explanation: The pop() method removes and returns the last element in a list.
Which of the following is a valid Python variable name?
Correct answer:
B) _var_name
Explanation: A valid Python variable name starts with a letter or underscore and contains letters, digits, or underscores.
What does x = [1, 2, 3] represent in Python?
Correct answer:
B) A list
Explanation: A list in Python is created using square brackets, such as [1, 2, 3] .
Which operator is used for floor division in Python?
Correct answer:
B) //
Explanation: The // operator performs floor division, which rounds the result down to the nearest whole number.
Which method is used to reverse a list in Python?
Correct answer:
A) reverse()
Explanation: The reverse() method reverses the order of the elements in a list.
What does the random.randint() function do?
Correct answer:
B) Returns a random integer between a specified range
Explanation: The random.randint() function generates a random integer within a specified range.
Which function can be used to generate a random float number between 0 and 1 in Python?
Correct answer:
C) random()
Explanation: The random() function generates a random float number between 0.0 and 1.0.
What is the default value returned by a Python function if no return statement is specified?
Correct answer:
C) None
Explanation: If a Python function does not have a return statement, it returns None by default.
How do you create a tuple in Python?
Correct answer:
B) Using parentheses ()
Explanation: A tuple is created by placing values inside parentheses, such as (1, 2, 3) .
Which method is used to find the position of a character in a string?
Correct answer:
A) find()
Explanation: The find() method returns the index of the first occurrence of a substring in a string.
What is the output of the following code: print(2 ** 3) ?
Correct answer:
C) 8
Explanation: The ** operator raises a number to a power, so 2 ** 3 equals 8.
Which function returns the type of an object in Python?
Correct answer:
A) type()
Explanation: The type() function returns the type of an object, such as int , float , or str .
Which method removes whitespace from the beginning and end of a string in Python?
Correct answer:
A) strip()
Explanation: The strip() method removes leading and trailing whitespace from a string.
What is the purpose of the continue statement in a loop?
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.
What type of data does the input() function return?
Correct answer:
C) String
Explanation: The input() function always returns user input as a string.
What is a comment in Python denoted by?
Correct answer:
A) #
Explanation: A comment in Python is denoted by the # symbol.
Which operator is used to get the remainder of a division in Python?
Correct answer:
B) %
Explanation: The modulus operator % returns the remainder of a division.
What does str(5) return in Python?
Correct answer:
A) The string ‘5’
Explanation: The str() function converts an integer or float to a string.
Which method can be used to convert a string to lowercase in Python?
Correct answer:
C) lower()
Explanation: The lower() method converts all characters in a string to lowercase.
Which keyword is used to handle exceptions in Python?
Correct answer:
C) except
Explanation: The except keyword is used to handle exceptions in Python.
What will be the output of print(4 % 2) ?
Correct answer:
B) 0
Explanation: 4 % 2 returns 0 because 4 is divisible by 2 with no remainder.
Which function in Python generates a range of numbers?
Correct answer:
A) range()
Explanation: The range() function generates a sequence of numbers.
What is the output of the following code: print(10 // 3) ?
Correct answer:
B) 3
Explanation: // is the floor division operator, which returns the largest integer less than or equal to the division result.
Which method would you use to convert a string to an integer in Python?
Correct answer:
B) int()
Explanation: The int() method converts a valid string or float to an integer.
What is the purpose of the elif statement in Python?
Correct answer:
A) To check multiple conditions
Explanation: The elif statement allows the program to test multiple conditions in an if-elif-else structure.
Which keyword is used to define a class in Python?
Correct answer:
B) class
Explanation: The class keyword is used to define a class in Python, which is a blueprint for creating objects.
If this exam is giving you a hard time, let us be your helping hand. Contact us, and we'll provide the assistance you need to pass and move forward.