Font size
Worksheetspython
Total questions: 82
Worksheet time: 40mins
print(Hello world!)
print("Hello world!" * 2)
people = ["John", "Rob", "Bob"]
print (people[-1])
what would this result be?
print(3*4+5)
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
What is the output?
True
False
condition1
condition2
Find T ?
T=144 / 2 + 5 * 9 - ( 8 -3 )
106
688
112
684
Find the Output:
Item = {"ECE" , "CSE" , "EEE" , "CIVIL"}
Item.add (2,"MECH")
print(Item)
{ "ECE" , "MECH" , "CSE" , "EEE" , "CIVIL" }
{ "ECE" , "CSE" , "MECH" , "EEE" , "CIVIL" }
{ "ECE" , "CSE" , "EEE" , "CIVIL" }
{ "ECE" , "CSE" , "EEE" ,"MECH" , "CIVIL" }
Find the Output ?
A = "Anand Institute of higher technology"
print ( A[-5:7]
_Institute of higher techn
nstitute of higher technol
d Institute of higher techn
Institute of higher techno
def.number (r1 , r2)
sum = r1 / r2
return sum
a = number (r2 = 15 , r1 = 10)
2 / 3
3 / 2
error
2
what is the output of the following code ?
var1 = 1
var2 = 2
var3 = "3"
print (var + var2 var3)
Error. Mixing operators between numbers and strings are not supported
6
33
123
Which of the following function convert a string to a float in python ?
float(X)
int(x[,base])
long(X[,base])
str(X)
what is the output of the following programing ?
X = [ 'ab' , 'cd' ]
for i in X:
i.upper()
print (x)
[ 'AB' , 'CD' ]
[ 'ab' , 'cd' ]
[ AB , CD ]
ERROR
find p ?
p = ( 35 , 46 , 73 , 21 )
p.append( -2 , 24 )
print (p)
( 35 , 46 , 73 , 24 , 21 )
error
( 35 , 46 , 24 , 73 , 21 )
( 35 , 24 , 73 , 21 )
what will be the output of the following python code snippet ?
not (10 < 20) and not (10 > 30 )
TRUE
FALSE
Find the output ?
a = True
b = False
c = False
if a or b and c :
print "INFYTQ"
else:
print "infytq"
infytq
INFYTQ
ERROR
Which of the following are true for objects of Python’s set type:
The order of elements in a set is significant.
A given element can’t appear in a set more than once.
Sets are mutable.
A set may contain elements that are mutable.
What will be the output of the following Python code? *
x={1,3,5}
y={2,4,6}
x+y
{1,3,5,2,4}
{1,3,5,2,4,6}
Error as the duplicate item 6 is present in both sets
Error as unsupported operand type(s) for +: 'set' and 'set'
Which of the following functions will return the symmetric difference between two sets, x and y? *
x | y
x ^ y
x & y
x – y
What will be the output of the following Python code?
x = {4,7,8,8,9}
print(x)
{4, 7, 9}
{8, 9, 4, 7}
{4, 7, 8, 8, 9}
Error
Which of the following statements is used to create an empty set?
{ }
set()
[ ]
( )
What will be the output of the following Python code?
x = {6,5}
y = {2,3,5,6}
x<y
{1,2}
True
False
Invalid operation
The _________ function removes the first element of a set and the last element of a list.
remove
pop
discard
dispose
Which of these about a set is not true?
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
If x={5,6,7,8}, which of the following statements is false?
print(len(x))
print(min(x))
x.remove(5)
x[2]=45
Which of the following is not the correct syntax for creating a set?
set([[1,2],[3,4]])
set([1,2,2,3,4])
set((1,2,3,4))
{1,2,3,4}
In Python, a variable must be declared before it is assigned a value:
False
True
None
Which of the following statements assigns the value 100 to the variable x in Python:
x := 100
x = 100
x << 100
let x = 100
x <- 100
In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type:
False
True
None
Consider the following sequence of statements:
n = 300
m = n
Following execution of these statements, Python has created how many objects and how many references?
Two objects, two references
One objects, two references
One objects, one references
Two objects, one references
What Python built-in function returns the unique number assigned to an object:
ref( )
identity( )
id( )
refnum( )
Which of the following are valid Python variable names:
router66
ver1.3
Age
return
home_address
You are reading Python code, and these statements appear scattered in different locations throughout the code:
employeenumber = 4398
.
.
.
EmployeeNumber = 4398
.
.
.
employeeNumber = 4398
These statements refer to different variables.
These statements refer to the same variable.
Which of the following styles does PEP8 recommend for multi-word variable names:
DistanceToNearestTown (Pascal Case)
distanceToNearestTown (Camel Case)
distance_to_nearest_town (Snake Case)
None
Which of the following are Python reserved words (keywords):
None
default
class
goto
and
Find the output of the code:
# abc.py
def func(n):
return n + 10
func('Hello')
(a)
Find the output of the code:
nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv']
print nameList[1][-1]
(a)
Find the output of the code:
for i in range(2):
print i
for i in range(4,6):
print i
0,1,4,5
0,1,2,4,5,6
0,1,2,3,4,5,6
2,4,6
Find the output of the code:
geekCodes = [1, 2, 3, 4]
geekCodes.append([5,6,7,8])
print len(geekCodes)
4
5
6
8
Find the output of the code:
check1 = ['Learn', 'Quiz', 'Practice', 'Contribute']
check2 = check1
check3 = check1[:]
check2[0] = 'Code'
check3[1] = 'Mcq'
count = 0
for c in (check1, check2, check3):
if c[0] == 'Code':
count += 1
if c[1] == 'Mcq':
count += 10
print count
10
11
12
13
What is the output of the code:
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
print d1 > d2
True
False
Not applicable
Find the output of the code:
D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}
D['1'] = 2
print(D[D[D[str(D[1])]]])
2
3
'2'
Key error
Find the output of the code:
D = dict()
for i in range (3):
for j in range(2):
D[i] = j
print(D)
{0: 0, 1: 0, 2: 0}
{0: 1, 1: 1, 2: 1}
{0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}
TypeError: Immutable object
Find the output of the code:
List = [True, 50, 10]
List.insert(2, 5)
print(List, "Sum is: ", sum(List))
[True, 50, 10, 5] Sum is: 66
[True, 50, 5, 10] Sum is: 65
TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’
[True, 50, 5, 10] Sum is: 66
Find the output of the code:
L = list('123456')
L[0] = L[5] = 0
L[3] = L[-2]
print(L)
[0, ‘2’, ‘3’, ‘4’, ‘5’, 0]
[‘6’, ‘2’, ‘3’, ‘5’, ‘5’, ‘6’]
[‘0’, ‘2’, ‘3’, ‘5’, ‘5’, ‘0’]
[0, ‘2’, ‘3’, ‘5’, ‘5’, 0]
Which of the following are true of Python lists?
A list may contain any type of object except another list
A given object may appear in a list more than once
All elements in a list must be of the same type
These represent the same list:
['a', 'b', 'c']
['c', 'a', 'b']
There is no conceptual limit to the size of a list
Assume the following list definition:
>>> a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']
Several short REPL sessions are shown below. Which display correct output?
>>> print(a[-6])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> a[:] is a
True
>>> print(a[4::-2])
['quux', 'baz', 'foo']
>>> print(a[-5:-3])
['bar', 'baz']
>>> max(a[2:4] + ['grault'])
'qux'
List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:
a[2] = []
a[2:2] = []
a[2:3] = []
del a[2]
a.remove(3)
Consider the following nested list definition:
x = [10, [3.141, 20, [30, 'baz', 2.718]], 'foo']
A schematic for this list is shown above:
What is the expression that returns the 'z' in 'baz'?
x[1][2][1]
x[1][2][1][2]
x[1][2][2]
x[1][1][2]
List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:
a[2:3] = []
a[2] = []
a.remove(3)
a[2:2] = []
del a[2]
List a is defined as follows:
a = ['a', 'b', 'c']
Which of the following statements adds 'd' and 'e' to the end of a, so that it then equals ['a', 'b', 'c', 'd', 'e']:
a += ['d', 'e']
a[-1:] = ['d', 'e']
a += 'de'
a.append(['d', 'e'])
a[len(a):] = ['d', 'e']
You have a list a defined as follows:
a = [1, 2, 7, 8]
Write a Python statement using slice assignment that will fill in the missing values so that a equals [1, 2, 3, 4, 5, 6, 7, 8].
a[2:2] = [3, 4, 5, 6]
a[1:2] = [3, 4, 5, 6]
a[2:3] = [3, 4, 5, 6]
a[3:5] = [3, 4, 5, 6]
Suppose you have the following tuple definition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second element ('bar') with the string 'qux':
t[1] = 'qux'
t(1) = 'qux'
t[1:1] = 'qux'
It’s a trick question—tuples can’t be modified.
Write Python code to create a tuple with a single element, the string 'foo', and assign it to a variable called t.
(a)
Consider this assignment statement:
a, b, c = (1, 2, 3, 4, 5, 6, 7, 8, 9)[1::3]
Following execution of this statement, what is the value of b:
5
4
3
6
7
Assume x and y are assigned as follows:
x = 5
y = -5
What is the effect of this statement:
x, y = (y, x)[::-1]
The values of x and y are swapped
The values of x and y are unchanged
Both x and y are -5
Both x and y are 5
Who is the founder of Python Programming Language?
Rasmus Ganilo
Dennis Ritchie
Guido van Rossum
James Gosling
File extension of Python program is ______
.py
.p
.pyx
.pyy
List index begins with _________.
0
1
-1
-2
Which method adds element at the end of the List?
add()
append()
new()
insert()
_________________is an anonymous function.
User Defined
Default
Lambda
Reserved
____________ is a collection which is unordered, changable and indexed.
Dictionary
List
Tuple
Set
Python 3.7 was released on
June 2016
June 2017
June 2018
June 2019
IN and NOT IN are membership operators.
TRUE
FALSE
IS is an Identity Operator.
True
False
List = [2.3, 4.445, 3, 5.33, 1.054, 2.5]
print(List.pop()) What willbe the answer?
2.3
2.5
1.054
4.445
What will be the anser for this code?
120
650
225
400
In Python_____________ are written with round brackets
tuples
dictionary
list
set
a=(1,2,3,2,4,5,2)
a.count(2)
What will be the answer?
2
1
3
4
Keys and Values are related to ________
tuple
dictionary
list
set
The def keyword, along with the function name is used to define the __________
file
block
function
variable
_______is used as a dummy place holder whenever a syntactical requirement of a certain programming element is to be fulfilled without assigning any operation
Pass
Break
While
Goto
What will be the Output?
1
2
3
4
List = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1]
print(List.count(1))
What will be the output?
1
2
3
4
x = lambda a, b : a * b
print(x(5, 8))
What will be the output?
35
13
40
45
____________does not hold duplicate values and is unordered.
Set
Tuple
Dictionary
List
