Strings Flashcards

1
Q

slicing

A

name [0:4]

‘Mich’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

stride

A
# Get every second element. The elments on index 1, 3, 5 ...
name [::2]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

incorporate slicing with strde

A
# Get every second element in the range from index 0 to index 4
name [0:5:2]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Concatenate

A
# Concatenate two strings
statement =name +"is the best"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Print strings 3 times

A
# Print the string for 3 times
3* "Michael Jackson"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

back slash

A

New line escape sequence
print(“ Michael Jackson \n is the best” )
Michael jackson
is the best

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

back slash ‘t’

A

New line escape sequence
print(“ Michael Jackson \n is the best” )
Michael jackson
is the best

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly