WorksheetsPython Programming Quiz
Total questions: 25
Worksheet time: 17mins
Which of the following is the output of the below Python code?
var1 = lambda var: var * 2
ret = lambda var: var * 3
result = 2
result = var1(result)
result = ret(result)
result = var1(result)
print(result)
24
12
7
36
48
Which of the following is the output of the below Python code?
[Note: Python 2.7.5 and above]
mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
print(mylist[int(-1/2)])
b
bbb
'bbb'
a
What is a correct syntax to output "Hello World" in Python?
p("Hello World")
print("Hello World")
echo("Hello World");
echo "Hello World"
How do you insert COMMENTS in Python code?
#This is a comment
/*This is a comment*/
//This is a comment
Which one is NOT a legal variable name?
my_var
my-var
_myvar
Myvar
How do you create a variable with the numeric value 5?
Both the other answers are correct
x = 5
x = int(5)
What is the correct file extension for Python files?
.pyt
.pyth
.py
.pt
What is the correct syntax to output the type of a variable or object in Python?
print(typeof(x))
print(typeof x)
print(typeOf(x))
print(type(x))
How do you create a variable with the floating number 2.8?
x = 2.8
x = float(2.8)
Both the other answers are correct
What is the correct way to create a function in Python?
function myfunction():
def myFunction():
create myFunction():
In Python, 'Hello', is the same as "Hello"
True
False
What is a correct syntax to return the first character in a string?
x = sub("Hello", 0, 1)
x = "Hello"[0]
x = "Hello".sub(0, 1)
Which of the following is the correct output of the call to below line of code?
print(list("hello"))
['h', 'e', 'l', 'l', 'o']
None of these
[h,e,l,l,o]
['h' 'e' 'l' 'l' 'o']
Which of the following is the output of the instructions given below?
mylist=[1, 5, 9, int('0')]
print(sum(mylist))
16
5
1
15
Determine the output of the below Python code fragment?
var1 = True
var2 = False
var3 = False
if var1 or var2 and var3:
print("True")
else:
print("False")
False
None of these
Runtime error
True
Which of the following statements best describes the behavior of the random.shuffle(mylist) as being used in the below code fragment?
import random
mylist = [10, 20, 30]
random.shuffle(mylist)
print(mylist)
return a list where elements 10, 20 and 30 would be at random positions.
It'll not modify the list. This function is just a placeholder and yet to be implemented.
shuffle the elements of the list in-place.
shuffle the elements for the no. of times equal to the size of the list.
Which of the following is the output of the Python code fragment given below?
var1 = 4.5
var2 = 2
print(var1//var2)
22.5
2.5
2.0
2.25
20.0
Which method can be used to remove any whitespace from both the beginning and the end of a string?
ptrim()
len()
trim()
strip()
Which method can be used to return a string in upper case letters?
upperCase()
uppercase()
toUpperCase()
upper()
Which of these collections defines a LIST?
("apple", "banana", "cherry")
{"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}
["apple", "banana", "cherry"]
Which of these collections defines a TUPLE?
{"name": "apple", "color": "green"}
("apple", "banana", "cherry")
["apple", "banana", "cherry"]
{"apple", "banana", "cherry"}
Which of these collections defines a SET?
{"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}
("apple", "banana", "cherry")
["apple", "banana", "cherry"]
Which of these collections defines a DICTIONARY?
["apple", "banana", "cherry"]
{"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}
("apple", "banana", "cherry")
Which collection is ordered, changeable, and allows duplicate members?
LIST
DICTIONARY
SET
TUPLE
How do you start writing a for loop in Python?
for x in y:
for each x in y:
for x > y:
