1Which of the following is a major difference between Python 2 and Python 3 regarding the print statement?
A.There is no difference
B.Python 2 uses parentheses for print, while Python 3 does not require them
C.Python 3 does not have a print function
D.Python 3 uses parentheses for print, while Python 2 does not require them
Correct Answer: Python 3 uses parentheses for print, while Python 2 does not require them
Explanation:
In Python 2, print is a statement (e.g., 'print 5'), whereas in Python 3, it is a function and requires parentheses (e.g., 'print(5)').
Incorrect! Try again.
2What is the standard file extension for Python scripts?
A..pyt
B..pn
C..py
D..pt
Correct Answer: .py
Explanation:
Python source code files utilize the .py extension.
Incorrect! Try again.
3Which command is typically used in the Windows Command Prompt to run a Python file named 'script.py'?
A.run script.py
B.execute script.py
C.python script.py
D.go script.py
Correct Answer: python script.py
Explanation:
The keyword 'python' invokes the Python interpreter on the specified file.
Incorrect! Try again.
4What is the correct syntax to output 'Hello World' in Python 3?
A.console.log('Hello World')
B.System.out.println('Hello World')
C.print('Hello World')
D.echo 'Hello World'
Correct Answer: print('Hello World')
Explanation:
Python uses the print() function to output text to the console.
Incorrect! Try again.
5Which symbol indicates that the Python interpreter is running in interactive mode?
A.$$$
B.---
C.###
D.>>>
Correct Answer: >>>
Explanation:
The triple chevron (>>>) is the primary prompt indicating the interpreter is ready for input.
Incorrect! Try again.
6Which of the following is a valid variable name in Python?
A.my-var
B.2my_var
C._my_var
D.my var
Correct Answer: _my_var
Explanation:
Variable names cannot start with a number, contain hyphens, or spaces. Starting with an underscore is valid.
Incorrect! Try again.
7What happens if you try to use a variable that has not been defined?
A.The program returns None
B.The program returns 0
C.A TypeError occurs
D.A NameError occurs
Correct Answer: A NameError occurs
Explanation:
A NameError indicates that the interpreter does not recognize the local or global name provided.
Incorrect! Try again.
8Which operator is used to assign a value to a variable?
A.->
B.=
C.==
D.:
Correct Answer: =
Explanation:
The single equals sign (=) is the assignment operator in Python.
Incorrect! Try again.
9Python is a case-sensitive language. What does this mean?
A.Keywords must always be uppercase
B.Variables must always be uppercase
C.'Variable' and 'variable' are different identifiers
D.'Variable' and 'variable' are the same
Correct Answer: 'Variable' and 'variable' are different identifiers
Explanation:
Case sensitivity means that uppercase and lowercase letters are treated as distinct characters.
Incorrect! Try again.
10Which of the following is a Python keyword?
A.integer
B.variable
C.print
D.yield
Correct Answer: yield
Explanation:
'yield' is a reserved keyword. 'print' is a built-in function, not a keyword, and 'variable'/'integer' are not reserved.
Incorrect! Try again.
11What function is used to check the data type of a value?
A.class()
B.type()
C.typeof()
D.check()
Correct Answer: type()
Explanation:
The type() function returns the class type of the argument passed to it.
Incorrect! Try again.
12What is the data type of the value 3.14?
A.str
B.float
C.bool
D.int
Correct Answer: float
Explanation:
Numbers with a decimal point belong to the float (floating-point) data type.
Incorrect! Try again.
13What is the data type of the value '10'?
A.str
B.int
C.float
D.bool
Correct Answer: str
Explanation:
Because the number is enclosed in quotes, Python treats it as a string.
Incorrect! Try again.
14Which of the following represents a Boolean value in Python?
A.true
B.1.0
C.TRUE
D.True
Correct Answer: True
Explanation:
Boolean values in Python are capitalized: True and False.
Incorrect! Try again.
15What is a 'statement' in Python?
A.A unit of code that the Python interpreter can execute
B.A syntax error
C.A math equation only
D.A comment line
Correct Answer: A unit of code that the Python interpreter can execute
Explanation:
A statement is an instruction that the Python interpreter can execute, such as assignment or import statements.
Incorrect! Try again.
16Which of the following is an example of an expression?
A.import os
B.x = 5
C.5 + 10
D.if x > 5:
Correct Answer: 5 + 10
Explanation:
An expression is a combination of values, variables, and operators that yields a result value.
Incorrect! Try again.
17What is the result of the floor division operation: 7 // 2?
A.4
B.2
C.3
D.3.5
Correct Answer: 3
Explanation:
Floor division (//) divides the numbers and rounds down to the nearest whole number.
Incorrect! Try again.
18Which operator calculates the remainder of a division?
A.//
B.%
C.#
D./
Correct Answer: %
Explanation:
The modulus operator (%) returns the remainder of the division.
Incorrect! Try again.
19What is the result of 2 ** 3?
A.5
B.9
C.6
D.8
Correct Answer: 8
Explanation:
The double asterisk (**) is the exponentiation operator. 2 to the power of 3 is 8.
Incorrect! Try again.
20What is the output of the following code: print(10 / 2)?
A.5.0
B.2
C.10
D.5
Correct Answer: 5.0
Explanation:
In Python 3, the standard division operator (/) always returns a float, even if the result is a whole number.
Incorrect! Try again.
21Following the order of operations (PEMDAS), what is the result of 2 + 3 * 4?
A.24
B.14
C.20
D.10
Correct Answer: 14
Explanation:
Multiplication () has higher precedence than addition (+). 3 4 = 12, then 12 + 2 = 14.
Incorrect! Try again.
22Which character starts a single-line comment in Python?
A.--
B.//
C.#
D./*
Correct Answer: #
Explanation:
The hash symbol (#) indicates the start of a comment in Python.
Incorrect! Try again.
23What happens when you use the '+' operator on two strings?
A.It concatenates the strings
B.It subtracts them
C.It adds the ASCII values
D.It throws a TypeError
Correct Answer: It concatenates the strings
Explanation:
When applied to strings, '+' joins them end-to-end (concatenation).
Incorrect! Try again.
24What happens when you use the '' operator on a string and an integer (e.g., 'Hi' 3)?
A.It adds the number to the string
B.It repeats the string 3 times
C.It creates a list
D.TypeError
Correct Answer: It repeats the string 3 times
Explanation:
The '*' operator performs repetition when used with a string and an integer. Result: 'HiHiHi'.
Incorrect! Try again.
25What is the result of executing: print('5' + 5)?
A.TypeError
B.10
C.NaN
D.55
Correct Answer: TypeError
Explanation:
Python cannot implicitly convert an integer to a string (or vice versa) for concatenation using the '+' operator.
Incorrect! Try again.
26Variables in Python are 'dynamically typed'. What does this mean?
A.A variable can hold different types of values at different times
B.You must declare the type before assigning a value
C.Variables cannot change values
D.Variables are strictly typed like C++
Correct Answer: A variable can hold different types of values at different times
Explanation:
Python determines the type based on the value assigned, and you can reassign a variable to a value of a different type later.
Incorrect! Try again.
27Which naming convention is recommended for Python variable names?
A.camelCase
B.snake_case
C.kebab-case
D.PascalCase
Correct Answer: snake_case
Explanation:
PEP 8 style guide recommends snake_case (lowercase with underscores) for variable names.
Incorrect! Try again.
28What is the associativity of the exponentiation operator (**) in Python?
A.Right-to-left
B.Left-to-right
C.Center
D.Random
Correct Answer: Right-to-left
Explanation:
Exponentiation is evaluated from right to left. 232 is calculated as 2(32).
Incorrect! Try again.
29What is 'Composition' in the context of Python expressions?
A.Compiling code to C
B.Combining simple expressions and statements into compound ones
C.Installing Python packages
D.Writing comments
Correct Answer: Combining simple expressions and statements into compound ones
Explanation:
Composition allows you to nest functions or expressions, like print(type(x)).
Incorrect! Try again.
30Which of the following variable names leads to a SyntaxError?
A.Class_Name
B.class
C.klass
D.clazz
Correct Answer: class
Explanation:
'class' is a reserved keyword in Python and cannot be used as a variable name.
Incorrect! Try again.
31What does the function input() return by default?
A.float
B.int
C.list
D.str
Correct Answer: str
Explanation:
The input() function always captures user input as a string.
Incorrect! Try again.
32Why are comments important in programming?
A.They explain what the code does to humans
B.They are required by the compiler
C.They make the code run faster
D.They encrypt the code
Correct Answer: They explain what the code does to humans
Explanation:
Comments are ignored by the interpreter and serve as documentation for developers.
Incorrect! Try again.
33What is the result of: 10 % 3?
A.3.33
B.10
C.1
D.3
Correct Answer: 1
Explanation:
10 divided by 3 is 3 with a remainder of 1.
Incorrect! Try again.
34Which of the following is NOT an assignment statement?
A.17 + 3
B.message = 'Hello'
C.n = 17
D.pi = 3.14159
Correct Answer: 17 + 3
Explanation:
'17 + 3' is an expression that evaluates to a value but does not assign it to any variable.
Incorrect! Try again.
35How do you represent a string literal in Python?
A.Parentheses
B.Either single or double quotes
C.Only single quotes
D.Only double quotes
Correct Answer: Either single or double quotes
Explanation:
Python accepts both 'string' and "string" as valid string literals.
Incorrect! Try again.
36What identifies the values acted upon by an operator?
A.Functions
B.Keywords
C.Comments
D.Operands
Correct Answer: Operands
Explanation:
In the expression 'a + b', 'a' and 'b' are the operands.
Incorrect! Try again.
37If x = 10 and y = 20, what is the result of: print(x, y)?
A.30
B.x y
C.10 20
D.1020
Correct Answer: 10 20
Explanation:
The print function separates multiple arguments with a space by default.
Incorrect! Try again.
38Which of the following creates a multi-line string or comment?
A.''' (triple quotes)
B.#
C.//
D.<!-- -->
Correct Answer: ''' (triple quotes)
Explanation:
Triple quotes (single or double) are used for multi-line strings, often used as multi-line comments or docstrings.
Incorrect! Try again.
39What error is raised if you write: print 'Hello' in Python 3?
A.TypeError
B.SyntaxError
C.NameError
D.ValueError
Correct Answer: SyntaxError
Explanation:
Missing parentheses in a call to print() is a syntax error in Python 3.
Incorrect! Try again.
40What is the binary operator for multiplication?
A.mul
B.*
C.x
D.#
Correct Answer: *
Explanation:
The asterisk (*) is the symbol for multiplication in Python.
Incorrect! Try again.
41Which of the following is an illegal variable name?
A.22_catch
B.CATCH22
C.catch_22
D._catch22
Correct Answer: 22_catch
Explanation:
Variable names must not start with a digit.
Incorrect! Try again.
42If you define variable x = 10 and then x = 'Hello', what happens?
A.x now holds the string 'Hello'
B.x keeps the value 10
C.Error: Type mismatch
D.The program crashes
Correct Answer: x now holds the string 'Hello'
Explanation:
Python allows variables to be reassigned to values of different types.
Incorrect! Try again.
43The term 'IDLE' in Python stands for:
A.Interactive Design Language Environment
B.Internal Developer Loop Engine
C.Integrated Development and Learning Environment
D.Integrated Debugging Line Editor
Correct Answer: Integrated Development and Learning Environment
Explanation:
IDLE is Python's standard IDE.
Incorrect! Try again.
44Which of the following statements assigns the string 'Python' to the variable named language?
A.set language 'Python'
B.language == 'Python'
C.language = 'Python'
D.'Python' = language
Correct Answer: language = 'Python'
Explanation:
The variable name goes on the left, followed by '=', followed by the value.
Incorrect! Try again.
45What will be the output of: print(3 * '7')?
A.777
B.37
C.Syntax Error
D.21
Correct Answer: 777
Explanation:
The string '7' is repeated 3 times.
Incorrect! Try again.
46Which character is used to separate two statements on a single line?
A./
B.:
C.,
D.;
Correct Answer: ;
Explanation:
The semicolon (;) can be used to separate multiple statements on one line, though it is generally discouraged in Python style.
Incorrect! Try again.
47In the expression (5 + 2) * 3, which operation happens first?
A.Evaluation from left to right regardless
B.Addition
C.Multiplication
D.None
Correct Answer: Addition
Explanation:
Parentheses have the highest precedence, forcing addition to happen before multiplication.
Incorrect! Try again.
48What will the following code output? print(type('5.5'))
A.<class 'float'>
B.<class 'str'>
C.<class 'int'>
D.<class 'bool'>
Correct Answer: <class 'str'>
Explanation:
Despite containing a number, the quotes make it a string.
Incorrect! Try again.
49What does a SyntaxError generally indicate?
A.The code violates the grammatical rules of Python
B.The variable name is not found
C.The logic of the program is wrong
D.There is a division by zero
Correct Answer: The code violates the grammatical rules of Python
Explanation:
Syntax errors occur when the parser detects code that does not conform to Python language rules.
Incorrect! Try again.
50When you install Python on Windows, what needs to be added to the PATH variable to run python from any command prompt?
A.The browser history
B.Nothing, it works automatically
C.The My Documents folder
D.The directory where python.exe is located
Correct Answer: The directory where python.exe is located
Explanation:
Adding the Python installation directory to the system PATH environment variable allows the 'python' command to be recognized globally.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →