wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Strings and Lists

Total questions: 43

Worksheet time: 22mins

Name
Class
Date
1.

Which of the operator can be used in Strings?

a)

+

b)

*

c)

Both of the above

d)

None of the above

2.

When we create a program to extract each alphabet from a given string, what is it known as?

a)

Transpose

b)

Traverse

c)

Translate

d)

Terminate

3.

Which method is used to convert a given string in Capital letters?

a)

Capital

b)

Upper

c)

ConverttoUpper

d)

Capitalize

4.

s1="Hello"

n1=10

print(s1+n1)

What is the error in this code?

a)

Print statement not written in quotes

b)

Numeric value not written in quotes

c)

colon not written after the print statement

d)

string cannot be added to a number

5.

Which brackets are used for Lists?

a)

( )

b)

[ ]

c)

{ }

d)

None of the above

6.

[1, 2, 8, 9] < [9, 1]


What will be the result if we compare these two lists?

a)

True

b)

False

7.

[1, 2, 8, 9] < [1, 2, 8, 4]


What will be the result if we compare these two lists?

a)

True

b)

False

8.

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':

a)

t[1] = 'qux'

b)

t(1) = 'qux'

c)

t[1:1] = 'qux'

d)

It’s a trick question—tuples can’t be modified.

9.

If list1=[10,20,30,40,50]

then list1[2]=35 will result in:

a)

[35,10,20,30,40,50]

b)

[10,20,30,40,50,35]

c)

[10,20,35,40,50]

d)

[10,35,30,40,50]

10.

If list1=[17,23,41,10]

then list1.append(32) will result in:

a)

[32,17,23,41,10]

b)

[17,23,41,10,32]

c)

[10,17,23,32,41]

d)

[41,32,23,17,10]

11.

Which of the following expressions results in an error?

a)

float('12')

b)

int('12')

c)

float('12.5')

d)

int('12.5')

12.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

13.

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"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

14.

Consider this list, what will be the highest index the list can have:

li=[1,2,3,4,5]

a)

2

b)

3

c)

4

d)

5

15.

The count() method returns the number of times the specified element appears in the list.

What is the output of this code?

a)

3

b)

2

c)

1

d)

0

16.

What is the output of this code?

a)

X

b)

Y

c)

Error

17.

Which of the following function is used to count the number of elements in a list ?

a)

count( )

b)

find( )

c)

len( )

d)

index( )

18.

mylist = ["a","b"]

mylist[1] = "c"'

print(mylist)

a)

["a","c"]

b)

["a","b"]

c)

["a","b","c"]

d)

mylist

19.

What is the output of program below?


bicycles = ['trek', 'cannondale', 'redline', 'specialized']

print(bicycles[-1])

a)

trek

b)

cannondale

c)

redline

d)

specialized

20.

a = [2, 5, 8, 1]

print("a[2]")

What is the output above?

a)

5

b)

8

c)

a[2]

d)

2

21.

Which of these is the best description of a list in Python?

a)

A list is a collection of data that has an order and can be changed

b)

A list is a lot of variables

c)

A list is used for shopping

d)

A list is a collection of data that cannot hold duplicated data and cannot be changed

22.

Which of the following is not a comparison operator?

a)

<

b)

>

c)

==

d)

!==

23.

Which of the operator can be used in Strings?

a)

+

b)

*

c)

Both of the above

d)

None of the above

24.

When we create a program to extract each alphabet from a given string, what is it known as?

a)

Transpose

b)

Traverse

c)

Translate

d)

Terminate

25.

Which of the following is not a comparison operator?

a)

<

b)

>

c)

==

d)

!==

26.

word = "amazing"

For the given string if we run word[2:5] what does it mean?

a)

It will extract alphabets from index 2 to index 4

b)

It will extract alphabets from index 2 to index 5

c)

It will extract alphabets from position 2 to position 4

d)

It will extract alphabets from position 2 to position 5

27.

word = "amazing"

For the given string if we run word[2:5:2] what does 2 mean in this function?

a)

It will pick only second alphabet

b)

It will pick only two alphabets

c)

It will pick every alternate alphabet

d)

It will pick first two alphabets

28.

Which method is used to convert a given string in Capital letters?

a)

Capital

b)

Upper

c)

ConverttoUpper

d)

Capitalize

29.

Which of the following is not a valid string function?

a)

isalphanumeric

b)

isspace

c)

islower

d)

isalnum

30.

string="HELlo"

What will be the result of string.isupper()?

(a)  

31.

s1="Hello"

n1=10

print(s1+n1)

What is the error in this code?

a)

Print statement not written in quotes

b)

Numeric value not written in quotes

c)

colon not written after the print statement

d)

string cannot be added to a number

32.

s1="Hello"

s2="10"

print(s1+n1)

What is the error in this code?

a)

String 2 written in quotes

b)

String cannot be multiplied with a string

c)

colon not written after print statement

d)

Number written in quotes

33.

Which brackets are used for Lists?

a)

( )

b)

[ ]

c)

{ }

d)

None of the above

34.

Which of the following does not work in Lists?

a)

lstrip & rstrip

b)

+ & * symbol

c)

Membership operators

d)

Slicing

35.

Lists are?

a)

Mutable

b)

immutable

36.

[1, 2, 8, 9] < [9, 1]


What will be the result if we compare these two lists?

a)

True

b)

False

37.

[1, 2, 8, 9] < [1, 2, 8, 4]


What will be the result if we compare these two lists?

a)

True

b)

False

38.

Which of the following operator is valid in Lists?

a)

/

b)

**

c)

+

d)

-

39.

Which method is used to delete a value from the list and display it also?

a)

del()

b)

pop()

c)

popshow()

d)

remove()

40.

Which method is used to merge two lists?

a)

append

b)

merge

c)

join

d)

extend

41.

How many elements can be inserted using append() method?

a)

1

b)

2

c)

3

d)

Any number of elements

42.

Which method is used to add a value at a specified position in the list?

a)

append

b)

extend

c)

insert

d)

pop

43.

Identify the string membership operators of Python

a)

in, not in

b)

like, not like

c)

as, not as

d)

between, not between