WorksheetsPython Programming Quiz
Total questions: 20
Worksheet time: 10mins
Which of the following is the correct extension of the Python file?
.python
.py (correct)
.p
.pl
What will be the output of the following Python code? a, b = 6, 7 a, b = b, a a, b
(6, 7)
Nothing is printed
Invalid syntax
(7, 6) (correct)
Which of the following is the truncation division operator in Python?
// (correct)
%
/
|
Is Python case sensitive when dealing with identifiers?
no
yes (correct)
none of the mentioned
machine dependent
Which keyword is used to define a function in Python language?
Fun
Function
Define
def (correct)
Python supports the creation of anonymous functions at runtime, using a construct called ________
anonymous
pi
lambda (correct)
none of the mentioned
Which one of the following is the use of function in Python?
All of the mentioned (correct)
you can't also create your own functions
Functions are reusable pieces of programs
Functions don't provide better modularity for your application
Which of the following functions is a built-in function in Python?
sqrt()
seed()
(soru dosyada eksik/verilmemiş)
Consider the code: class tester: def init(self, id): self.id = str(id) id = "224" temp = tester(12) print(temp.id)
224
12 (correct)
error
None
All keywords in Python are in
None of the mentioned
lower case (correct)
Capitalized
UPPER CASE
To include the use of functions which are present in the random library, we must use the option:
random.h
import.random
import random (correct)
random.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.
All of the mentioned. (correct)
The @property decorator allows you to define getter, setter, and deleter methods for attributes.
del method is used to destroy instances of a class.
True
False (correct)
Which of the following is true for variable names in Python?
none of the mentioned
unlimited length (correct)
all private members must have leading and trailing underscores
underscore and ampersand are the only two special characters allowed
Which type of programming does Python support?
functional programming
structured programming
object-oriented programming
all of the mentioned (correct)
What type does the variable have when the following code line is executed? x = 2 * 3.0
str
int
float (correct)
bool
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)
error
0 1 2 (correct)
none of the mentioned
0 1 2 0
Which of the following character is used to give single-line comments in Python?
!
# (correct)
//
/*
What is the correct order of operations in Python?
Parentheses, Exponential, Multiplication, Division, Addition, Subtraction (correct)
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 (correct)
error, there is more than one return statement in a single try-finally block
