Strings Flashcards
1
Q
slicing
A
name [0:4]
‘Mich’
2
Q
stride
A
# Get every second element. The elments on index 1, 3, 5 ... name [::2]
3
Q
incorporate slicing with strde
A
# Get every second element in the range from index 0 to index 4 name [0:5:2]
4
Q
Concatenate
A
# Concatenate two strings statement =name +"is the best"
5
Q
Print strings 3 times
A
# Print the string for 3 times 3* "Michael Jackson"
6
Q
back slash
A
New line escape sequence
print(“ Michael Jackson \n is the best” )
Michael jackson
is the best
7
Q
back slash ‘t’
A
New line escape sequence
print(“ Michael Jackson \n is the best” )
Michael jackson
is the best
8
Q
upper
A
# Convert all the characters in string to upper case a = "Thriller is the sixth studio album" print ("before upper:", a) b = a. upper () print ("after upper:", b)
9
Q
replace
A
# Replace the old substring with the new target substring is the segment has been found in the string a= "Michael Jackson is the best" b=a.replace ('Michael', 'Janet') b
10
Q
find
A
# Find the substring in the string. Only the index of the first elment of substring in string will be the output name ="Michael Jackson" name .find ('el')