WorksheetsPython MCQ Quiz - 45 Sorular
Total questions: 27
Worksheet time: 54mins
Which of the following is the correct extension of the Python file?
.p
.pl
.python
.py
What will be the output of the following Python code? a, b = 6, 7 a, b = b, a a, b
(6, 7)
Invalid syntax
(7, 6)
Nothing is printed
Which of the following is the truncation division operator in Python?
/
//
%
|
Is Python case sensitive when dealing with identifiers?
none of the mentioned
yes
no
machine dependent
Which keyword is used to define a function in Python language?
Define
def
Function
Fun
Python supports the creation of anonymous functions at runtime, using a construct called ________
none of the mentioned
anonymous
pi
lambda
Which one of the following is the use of function in Python?
Functions are reusable pieces of programs
All of the mentioned
you can't also create your own functions
Functions don't provide better modularity for your application
Which of the following functions is a built-in function in Python?
seed()
sqrt()
Consider the code: class tester: def __init__(self, id): self.id = str(id) id = "224" temp = tester(12) print(temp.id)
None
224
error
12
All keywords in Python are in
lower case
UPPER CASE
Capitalized
None of the mentioned
To include the use of functions which are present in the random library, we must use the option:
random.random
random.h
import.random
import random
Which of the following statements about properties is true?
You use properties when you need controlled access or want to encapsulate logic without changing the API.
Properties are useful for validating data, computing attributes, and creating read-only or read-write attributes.
The @property decorator allows you to define getter, setter, and deleter methods for attributes.
All of the mentioned.
del method is used to destroy instances of a class.
True
False
Which of the following is true for variable names in Python?
none of the mentioned
all private members must have leading and trailing underscores
underscore and ampersand are the only two special characters allowed
unlimited length
Which type of programming does Python support?
functional programming
object-oriented programming
all of the mentioned
structured programming
What type does the variable have when the following code line is executed? x = 2 * 3.0
float
bool
str
int
What will be the output of the following Python program? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)
none of the mentioned
error
0 1 2 0
0 1 2
Which of the following character is used to give single-line comments in Python?
//
/*
#
!
What is the correct order of operations in Python?
Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
Parentheses, Exponential, Multiplication, Addition, Division, Subtraction
Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
What will be the output of the following Python code? def foo(): try: return 1 finally: return 2 k = foo() print(k)
1
3
2
error, there is more than one return statement in a single try-finally block
What will be the output of the following Python code? def add(c, k): c.test = c.test + 1 k = k + 1 class A: def __init__(self): self.test = 0 def main(): Count = A() k = 0 for i in range(0, 25): add(Count, k) print("Count.test =", Count.test) print("k =", k) main()
Count.test = 0, k = 0
Exception is thrown
Count.test = 25, k = 25
Count.test = 25, k = 0
Which of the following is a feature of Python DocString?
It provides a convenient way of associating documentation with Python modules, functions, classes, and methods.
All of the mentioned (CORRECT)
Docstrings can be accessed by the doc attribute on objects
In Python all functions should have a docstring
What will be the value of the following Python expression? 9 + 3 % 5
12 (CORRECT)
2
4
1
Which of the following statements are true about opening files?
When you open a file for reading, if the file does not exist, an error occurs.
When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
All of the mentioned (CORRECT)
When you open a file for writing, if the file does not exist, a new file is created.
Consider: A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Which of the following Python statements will result in the output 6?
A[3][2]
A[1][2]
A[2][1] (CORRECT)
A[2][3]
Which of the following is used to define a block of code in Python language?
Key
Brackets
Indentation
All of the mentioned
Which of the following is the use of id() function in Python?
The id() function compares two objects.
The Python id function returns the unique identity of the object.
Not every object in Python has a unique id.
None of the mentioned
