WorksheetsString Manipulation (Python)
Total questions: 17
Worksheet time: 13mins
how we store string value in variable?
'string'
"string"
%string%
#sring#
index of a string begins with
1
0
a
-1
The pseudocode below assigns two strings to two variables:
title = "computer science"
level = "gcse"
What would the Python code: len(level) return?
2
3
4
1
The pseudocode below assigns two strings to two variables:
title = "computer science"
level = "gcse"
What is title[0]?
'c'
'o'
'g'
An error
The pseudocode below assigns two strings to two variables:
title = "computer science"
level = "gcse"
What is title[4]?
'p'
'u'
't'
An error
string = "abcdef"
What is index of "f" ?
(a)
string = "Computer Science"
What is string[0:8] ?
(a)
Sequences of characters within a string can be accessed by taking a string ______ using [ ]
slice
cut
chop
substring
string1 = "Monty"
string2 = "Python"
string3 = string1 + string2
What is value of string3?
Monty Python
MontyPython
Monty+Python
string3
What does the isdigit() function do in Python?
Returns True if all the characters in the string are in capital letters
Returns True if all the characters in the string are in small letters
Returns True if the string contains only spaces
Returns True if all the characters in the string are digits
What is the output of the code fragment: print('hello'*3, str(123))?
hellohellohello, 123
hellohellohello, hellohellohello
hellohellohello, 123123123
hellohellohello, hello
Which of these will print the length of a string
print(len("a string"))
print("a string".len())
print(length("a string"))
x = len.string()
Which code would get the characters from position 2 to position 5 (not included).
x = txt[2:5]
x = txt[1:5]
x = txt[1:4]
x = txt[0[:4]
Convert the value of txt to upper case.
x = txt.upper()
x = txt.lower()
x = upper(txt)
x = upper.txt()
Replace the character H with a J
x = txt.replace("H", "J")
x = txt.replace("J", "H")
x = replace ("H", "J")
x = txt.replace(H,J)
