This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1 The given declaration statement in Python Language belongs to which data type?
>>>Student ={‘SUBJECT’ : ‘Compiler’, ‘Marks’ : ‘50’, ‘Grade’ : ‘C’}
Numbers
Sequence
Sets
Dictionary
Option D
In Python, a Dictionary is a data type used to store data in the form of key–value pairs. Dictionaries are enclosed within curly braces { }. Each key is associated with a value using a colon : (colon).
In the given statement Student = {'SUBJECT':'Compiler', 'Marks':'50', 'Grade':'C'}
Q: 2 What will be the output of the following Python code?
a = True
b = False
c = False
if not a or b:
print(1)
elif not a or not b and c:
print(2)
elif not a or b or not b and a:
print(3)
else:
print(4)
1
2
3
4
Option C
The precedence of logical operator in Python is:
Q: 3 What is output of the code in Python Language:
>>> str1 = ‘All the Best’
>>> str1[-3]
‘l’
‘e’
‘h’
‘B’
Option B
In Python, negative indexing is used to access characters from the end (right side) of a string.
| Positive Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Character | A | l | l | t | h | e | B | e | s | t | ||
| Negative Index | -12 | -11 | -10 | -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 |
The character at index str1[-3] is 'e'.
Q: 4 Which one is NOT a feature of Python Language?
High Level Language
Interpreted Language
Case—Insensitive
Portable
Option C
Python is a popular high-level programming language known for its simplicity and readability. It is a high-level, interpreted language and portable across different operating systems.
However, Python is case-sensitive language. This means uppercase and lowercase letters are treated differently.
>>>name = "Suresh"
>>>Name = "Rampayari"
>>print(name)
>>>print(Name)
Here, name and Name are treated as two different variables.
Q: 5 What is the meaning of >>> in Python Language?
Left Shift
Right Shift
Interpreter is ready to take instruction
Compiler is ready to take instruction
Option C
In Python, the symbol >>> is called the Python Prompt. It appears in the Python interpreter when Python is ready to accept and execute commands entered by the user.
It indicates that the interpreter is active and waiting for instructions.
Q: 6 Which of the following is the role of pickle module in Python?
Convert objects into an ordered sequence of bytes
Convert Python objects into JSON notation
Convert a byte stream into Python object hierarchy
Covert a list into a data table
Option A
The pickle module in Python is used for serializing and deserializing Python objects.
Q: 7 What is the output of this code in Python Language:
>>> x = 125
>>> y = 13
>>> x // = y
>>> x
9
125/13
10
9.62
Option A
In Python, the operator // is called the floor division. It divides the left operand by the right operand and provide the integer (floor) result.
The statement x //= y means x = x//y. Here, 125//13 gives 9 because floor division removes the decimal part and returns only the integer quotient. Therefore, the final value of x becomes 9.
Q: 8 What will be the output of the following Python script?
>>>L=[‘spam’, ‘Spam’, ‘SPAM!’]
>>>L[-2]
‘Spam’
‘spam’
‘SPAM!’
‘SP!’
Option A
In Python, negative indexes count from the end of the list.
Positive Indexing starts from left to right:
Index: 0 1 2
Value: 'spam' 'Spam' 'SPAM!'
Negative Indexing start from right to left:
Index: -3 -2 -1
Value: 'spam' 'Spam' 'SPAM!'
Q: 9 What is the output of the code in Python language:
for num in range (3):
if num > 0:
print (num*100, end=" ")
100 200 300
100 200
200
300 200 100
Option B
In Python, the range(3) function generates numbers starting from 0 up to 2. So the loop runs for 0,1, and 2.
| num Value | Condition num > 0 | Output |
|---|---|---|
| 0 | False | Nothing Printed |
| 1 | True | 1*100 = 100 |
| 2 | True | 2*100 = 200 |
Therefore, the printed output is 100 200
Q: 10 Which of the following declarations is incorrect in python language?
xyzp = 5,000,000
xyzp = 5000 6000 7000 8000
x, y, z, p = 5000, 6000, 7000, 8000
x_y_z_p = 5,000,000
Option B
In Python, writing xyzp = 5,000,000 is syntactically correct, but it does not store the integer 5000000. Instead, Python treats the commas as separators and creates a tuple (5, 0, 0). If we want to store 5000000 in python variable then correct way is either xyzp = 5000000 or xyzp = 5_000_000 for readability.
The statement, x, y, z, p = 5000, 6000, 7000, 8000 uses tuple unpacking, assigning each number to a separate variable: x = 5000, y = 6000, z = 7000, and p = 8000. This is a valid and commonly used Python syntax.
The statement, x_y_z_p = 5,000,000, is similar to statement xyzp = 5,000,000. It is syntactically correct, and the variable name is valid, but the value becomes a tuple (5, 0, 0).
The statement, xyzp = 5000 6000 7000 8000, is completely invalid in Python. The numbers cannot be written separated by spaces, and this will throw a syntax error.
Q: 11 Which statement(s) is/are NOT true about the variables in Python Language:
I. Values of every variable can be changed once a variable has been created and assigned value.
II. Assignment statement is used to create a new variable and assign value.
Only I
Only II
Both I And II
Neither I Nor II
Option A
In Python, variables are created using an assignment statement. The assignment operator = is used to assign a value to a variable. Therefore, Statement II is true because assignment statements are used to create variables and assign values.
The Statement I is that “Values of every variable can be changed once a variable has been created and assigned value.”
This statement is not always true because Python has both Mutable (list, dictionary, set) and Immutable (int, float, tuple, string) data types. The immutable objects cannot be changed after creation.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.