Font size
WorksheetsPython Strings and Lists
Total questions: 43
Worksheet time: 22mins
Which of the operator can be used in Strings?
+
*
Both of the above
None of the above
When we create a program to extract each alphabet from a given string, what is it known as?
Transpose
Traverse
Translate
Terminate
Which method is used to convert a given string in Capital letters?
Capital
Upper
ConverttoUpper
Capitalize
s1="Hello"
n1=10
print(s1+n1)
What is the error in this code?
Print statement not written in quotes
Numeric value not written in quotes
colon not written after the print statement
string cannot be added to a number
Which brackets are used for Lists?
( )
[ ]
{ }
None of the above
[1, 2, 8, 9] < [9, 1]
What will be the result if we compare these two lists?
True
False
[1, 2, 8, 9] < [1, 2, 8, 4]
What will be the result if we compare these two lists?
True
False
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 list1=[10,20,30,40,50]
then list1[2]=35 will result in:
[35,10,20,30,40,50]
[10,20,30,40,50,35]
[10,20,35,40,50]
[10,35,30,40,50]
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]
Which of the following expressions results in an error?
float('12')
int('12')
float('12.5')
int('12.5')
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
Consider this list, what will be the highest index the list can have:
li=[1,2,3,4,5]
2
3
4
5
The count() method returns the number of times the specified element appears in the list.
What is the output of this code?
3
2
1
0
What is the output of this code?
X
Y
Error
Which of the following function is used to count the number of elements in a list ?
count( )
find( )
len( )
index( )
mylist = ["a","b"]
mylist[1] = "c"'
print(mylist)
["a","c"]
["a","b"]
["a","b","c"]
mylist
What is the output of program below?
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles[-1])
trek
cannondale
redline
specialized
a = [2, 5, 8, 1]
print("a[2]")
What is the output above?
5
8
a[2]
2
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
Which of the following is not a comparison operator?
<
>
==
!==
Which of the operator can be used in Strings?
+
*
Both of the above
None of the above
When we create a program to extract each alphabet from a given string, what is it known as?
Transpose
Traverse
Translate
Terminate
Which of the following is not a comparison operator?
<
>
==
!==
word = "amazing"
For the given string if we run word[2:5] what does it mean?
It will extract alphabets from index 2 to index 4
It will extract alphabets from index 2 to index 5
It will extract alphabets from position 2 to position 4
It will extract alphabets from position 2 to position 5
word = "amazing"
For the given string if we run word[2:5:2] what does 2 mean in this function?
It will pick only second alphabet
It will pick only two alphabets
It will pick every alternate alphabet
It will pick first two alphabets
Which method is used to convert a given string in Capital letters?
Capital
Upper
ConverttoUpper
Capitalize
Which of the following is not a valid string function?
isalphanumeric
isspace
islower
isalnum
string="HELlo"
What will be the result of string.isupper()?
(a)
s1="Hello"
n1=10
print(s1+n1)
What is the error in this code?
Print statement not written in quotes
Numeric value not written in quotes
colon not written after the print statement
string cannot be added to a number
s1="Hello"
s2="10"
print(s1+n1)
What is the error in this code?
String 2 written in quotes
String cannot be multiplied with a string
colon not written after print statement
Number written in quotes
Which brackets are used for Lists?
( )
[ ]
{ }
None of the above
Which of the following does not work in Lists?
lstrip & rstrip
+ & * symbol
Membership operators
Slicing
Lists are?
Mutable
immutable
[1, 2, 8, 9] < [9, 1]
What will be the result if we compare these two lists?
True
False
[1, 2, 8, 9] < [1, 2, 8, 4]
What will be the result if we compare these two lists?
True
False
Which of the following operator is valid in Lists?
/
**
+
-
Which method is used to delete a value from the list and display it also?
del()
pop()
popshow()
remove()
Which method is used to merge two lists?
append
merge
join
extend
How many elements can be inserted using append() method?
1
2
3
Any number of elements
Which method is used to add a value at a specified position in the list?
append
extend
insert
pop
Identify the string membership operators of Python
in, not in
like, not like
as, not as
between, not between
