Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

String in Python

Total questions: 36

Worksheet time: 19mins

Name
Class
Date
1.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
2.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
3.

Each item in a string has an "address" or index. The first index in a Python string is what?

a)

0

b)

1

c)

a

d)

A

4.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
5.
What output will this code produce?
a)
3
b)
20
c)
25
d)
17
6.
What output will this code produce?
a)
1
b)
3
c)
2
d)
4
7.

Returning a range of characters (part of a string) is done using which syntax?

a)

Slice

b)

Splice

c)

Cut

d)

Select

8.

What is the output from this code?

a)

ell

b)

llo

c)

ello,

d)

Hello

9.

What is the output from this code?

a)

, W

b)

Wor

c)

orl

d)

lro

10.

Python accepts single ('), double (") and triple (''' or """) quotes to denote strings. Which of the following is NOT acceptable Python syntax?

a)

print('Hello World')

b)

print("Hello World")

c)

print('Hello World")

d)

print(""'Hello World'"")

11.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

12.

What is printed by the following statement?

print("A" in "APCSP")

a)

True

b)

False

c)

Error

13.

Evaluate the following expression:

"dog" < "Dog"

a)

They are the same word

b)

True

c)

False

14.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

15.

data = "No Way!" The expression len(data) evaluates to:

a)

7

b)

9

c)

8

d)

6

16.

Which operator returns True if target string is somewhere in the search string; otherwise it returns False.

a)

==

b)

!=

c)

in

d)

is

17.

What will the output be from the following code?

print("Hello world!" * 2)

a)

TypeError

b)

Hello world world!

c)

Hello world!Hello world!

d)

Hello world! * 2

18.

What will the output be from the following code?

print("Hello world!\nHello world!")

a)

Hello world! Hello world!

b)

Hello world!

Hello world!

c)

SyntaxError

d)

Hello world!

19.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

20.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3

21.

What will the output be from the following code?

print("Hello world!")

a)

SyntaxError

b)

Hello world!

c)

"Hello world!"

d)

print(Hello world!)

22.
What will the output be from the following code?
print("Hello" + "world" + "today")
a)
Helloworldtoday
b)
Hello world today
c)
"Hello" "world" "today"
d)
SyntaxError
23.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
24.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
25.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
26.
What is the name of the programming language we are learning?
a)
Scratch
b)
Python
c)
Pie thin
d)
Scribble
27.

What will be the output?

name = "Dave"

print (name)

a)

Dave

b)

'Dave'

c)

name

d)

(name)

28.

Is python an interpreter or compiler programming language?

a)

Compiler

b)

Interpreter

29.

Which of the operator can be used in Strings?

a)

+

b)

*

c)

Both of the above

d)

None of the above

30.

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

31.

Which of the following is not a comparison operator?

a)

<

b)

>

c)

==

d)

!==

32.

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

33.

string="HELlo"

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

(a)  

34.

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

35.

example = "helle"

print(example.rfind("e") )

a)

-4

b)

4

c)

3

d)

1

36.

What will the below Python code will return?

If str1="save paper,save plants"


print(str1.find("save"))

a)

It returns the first index position of the first occurance of "save" in the given string str1.

b)

It returns the last index position of the last occurance of "save" in the given string str1.

c)

It returns the last index position of the first occurance of "save" in the given string str1.

d)

It returns the first index position of the last occurance of "save" in the given string str1.