NEW
Font size
S
M
L
XL
WorksheetsProgram Development - Python: Strings
Total questions: 25
Worksheet time: 41mins
Name
Class
Date
1.
For strings, the
+ operator represents a)
Concatenation
b)
Addition
c)
Appending
d)
Recantation
2.
What is printed by the following statements?
s = "programming rocks"
print(len(s))
s = "programming rocks"
print(len(s))
a)
12
b)
17
c)
16
d)
nothing - there is an error
3.
What is printed by the following statements?
cheer = "Go Eagles!"
print(cheer[0:1])
cheer = "Go Eagles!"
print(cheer[0:1])
a)
G
b)
"Go"
c)
Go
d)
o
4.
What is printed by the following statements?
cheer = "Go Eagles!"
print(cheer[5:8])
cheer = "Go Eagles!"
print(cheer[5:8])
a)
gle
b)
agle
c)
gles
d)
agles
5.
What is printed by the following statements?
ss = "Hola, friend"
print(ss.upper())
ss = "Hola, friend"
print(ss.upper())
a)
hola, friend
b)
Hola, Friend
c)
HOLA, FRIEND
d)
Hola, friend
6.
What is printed by the following statements?
s = "python rocks"
print(s[-3])
s = "python rocks"
print(s[-3])
a)
c
b)
k
c)
s
d)
Error
7.
What is printed by the following statements?
s = "python rocks"
print(s[1] * s.index("n"))
s = "python rocks"
print(s[1] * s.index("n"))
a)
Error
b)
55555
c)
n
d)
yyyyy
8.
A data type consisting of numbers, letters and symbols.
a)
String
b)
Integer
c)
Float
d)
Boolean
9.
What is printed by the following statments:
fruit = "banana"
bakedGood = " nut bread"
print(fruit + bakedGood)
fruit = "banana"
bakedGood = " nut bread"
print(fruit + bakedGood)
a)
nut bread banana
b)
nut bread
c)
banana nut bread
d)
fruit bakedGood
10.
What is printed by the following statements:
s = "python rocks"
print(s[7:11] * 3)
s = "python rocks"
print(s[7:11] * 3)
a)
rockrockrock
b)
rock rock rock rock
c)
pythonrockrockrock
d)
pythonrocksrocksrocks
11.
Evaluate the following expression:
"dog" < "Dog"
"dog" < "Dog"
a)
True
b)
False
c)
They are the same word
12.
What is printed by the following statements:
s = "Call"
s[0] = "B"
print(s)
s = "Call"
s[0] = "B"
print(s)
a)
Ball
b)
Call
c)
Error
13.
What is printed by the following statements:
singers = "Peter, Paul, and Mary"
print(singers[0:5])
singers = "Peter, Paul, and Mary"
print(singers[0:5])
a)
Peter
b)
Paul
c)
Mary
d)
Error
14.
How many times is the word YES printed by the following statements?
s = "AP CSP"
for hmm in s:
print("YES")
s = "AP CSP"
for hmm in s:
print("YES")
a)
6
b)
12
c)
3
d)
Error
15.
How many times is the word BYE printed by the following statements?
s = "AP CSP 2018"
for ch in s[2:7]:
print("BYE")
s = "AP CSP 2018"
for ch in s[2:7]:
print("BYE")
a)
4
b)
5
c)
6
d)
Error
16.
What characters are printed by the following statements?
s = "APCSP2018"
for idx in range(len(s)):
if idx % 2 == 0:
print(s[idx])
s = "APCSP2018"
for idx in range(len(s)):
if idx % 2 == 0:
print(s[idx])
a)
ACP08
b)
PS21
c)
APCSP2018
d)
Error
17.
What characters are printed by the following statements?
s = "APCSP2018"
idx = 1
while idx < len(s):
print(s[idx])
idx = idx + 2
s = "APCSP2018"
idx = 1
while idx < len(s):
print(s[idx])
idx = idx + 2
a)
ACP08
b)
PS21
c)
APCSP2018
d)
Error
18.
What is printed by the following statement?
print("A" in "APCSP")
print("A" in "APCSP")
a)
True
b)
False
c)
Error
19.
What is printed by the following statement?
print("" in "APCSP")
print("" in "APCSP")
a)
True
b)
False
c)
Error
20.
What is printed by the following statement?
print("P" not in "APCSP")
print("P" not in "APCSP")
a)
True
b)
False
c)
Error
21.
What is printed by the following statement?
print("a" not in "APCSP")
print("a" not in "APCSP")
a)
True
b)
False
c)
Error
22.
What is printed by the following statements:
s = "ball"
r = ""
for item in s:
r = item.upper() + r
print(r)
s = "ball"
r = ""
for item in s:
r = item.upper() + r
print(r)
a)
BALL
b)
ball
c)
LLAB
d)
Error
23.
Which Data Type would the following be stored as: " Biscuit "
a)
String
b)
Integer
c)
Boolean
d)
Float
24.
What happens if you run the following code?
foo = "a string"
a)
foo and "a string" are printed
b)
"a string" is added onto to the end of foo
c)
The value "a string" is stored in the variable foo
d)
The user is asked to enter "foo" into the console
25.
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'"")
Reset
