WorksheetsPython
Total questions: 30
Worksheet time: 18mins
How do you access the first item in a list named shopping?
shopping[1]
shopping[0]
shopping[first]
shopping[-1]
Which statement prints 7 (Select 2 answers)
print 7
print("7"
print("7")
print(3 + 4)
Which of the following functions is used to count the number of elements in a list ?
count( )
find( )
len( )
index( )
The correct syntax for converting the string x to uppercase is :
upper.x()
upper(x)
x.UPPER[ ]
x.upper()
Unchangeable data stored in parentheses ( )
Containers
List
Tuple
Variable
Syntax
All whole numbers (both positive and negative) and zero. These numbers cannot have decimal places.
Integer
Float
Value
Error
Fraction
List items have an index number. In the following list, which item has the index number of 3?
["Barry", "Harry", "Jesse", "John", "Peter", "Harry"]
"Barry"
"Harry"
"Jesse"
"John"
If L1=[2, 4, 8, 16] and L2=[32, 64]
what will result from L1+L2?
[2,4,8,16,32,64]
[2,4,8,16][32,64]
[2,4,8,16],[32,64]
2468163264
What is the index number/ position for 'Spain'?
['England','Brazil','Spain','France']
0
1
2
3
Which of these codes is correct for creating a list of numbers?
num = (10,29,37,109)
num = [10,29,37,109]
num == (10,29,37,109)
num = ['10 29 37 109']
Let x= "Python", the output of print(x.upper()) is
python
PYTHON
_PYTHON
"PYTHON"
If list1=[17,23,41,10]
then list1.append(32) will result in:
[32,17,23,41,10]
[17,23,41,10,32]
[10,17,23,32,41]
[41,32,23,17,10]
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.
If L1=[2,4,8,16] what is the result of print(16 in L1)
True
False
Let x= "Python", the output of
print(x[0])
print(x[1])
print(x[2])
PYT
P
y
t
T
h
o
n
oh
In Python, this is the command that tells the program what to show on the screen
Expression
Script
Output
Input
How do you print out the last item on a list named shopping?
shopping[0]
shopping[last]
shopping[-1]
shopping[1]
Given s = "Python", choose the Python code that DOES NOT give the output 6
print(len(s))
print(s.len())
print(s.replace("Python","6"))
print(len(s[ : len(s)] ))
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList(1)
nameList[4]
nameList(4)
nameList["1"]
Which of these is a correct statement?
List and tuples both are changeable.
List is changeable whereas tuples are unchangeable.
List and tuples both are unchangeable.
List is unchangeable whereas tuples are changeable
Mutable data stored in square brackets [ ]
Containers
List
Tuple
Variable Assignment
Syntax
The correct syntax of the len function for string x:
x.len()
len[x]
LEN[]
len(x)
What is used to separate elements in a list?
Bracket
Comma
Full Stop
Space
If list=[10,20,30,40,50] then list[2]=35 will result
[35,10,20,30,40,50]
[10,20,30,40,50,35]
[10,20,35,40,50]
[10,35,30,40,50]
data = "No Way!" The expression len(data) evaluates to:
7
9
8
6
Numbers that contain floating decimal points, such as 5.5, 5000.5, or even 2.509233
Integer
Float
Value
Error
Fraction
What output will this code produce?
4
2
3
5
