4.1.2.Quiz String Operations - sj50179/IBM-Data-Science-Professional-Certificate GitHub Wiki

LATEST SUBMISSION GRADE 100% 1. Question 1 In Python, if you executed name = 'Lizz', what would be the output of print(name[0:2])?

1 / 1 point

Lizz

L

Li

Correct Correct, we only retrieve the first two elements.

Question 2 Consider the string A='1934567', what is the result of the following operation A[1::2] ?

1 / 1 point

'1934567'

'946'

'1357'

Correct Correct, the first index 1 from A[1::2] corresponds to the second value, i.e. 9 . The stride value of 2 from A[1::2] selects every second element.

Question 3 In Python, what is the result of the following operation: '1'+'2' ?

1 / 1 point

3

'3'

'12'

Correct correct, the '+' applied to strings does not add strings but concatenates them

Question 4 Given myvar = 'hello' , how would you return myvar as uppercase?

1 / 1 point

len(myvar)

myvar.find('hello')

myvar.upper()

Correct correct

Question 5 Consider the string Name="ABCDE", what is the result of the following operation Name.find("B") ?

1 / 1 point

1

2

0

Correct correct, the method finds the starting index of a substring

Question 6 What is the result of the following : str(1)+str(1) ?

1 / 1 point

'11'

2

Correct correct, the integers are cast to a string, and the strings are concatenated

Question 7 What is the result of the following: "ABC".replace("AB", "ab") ?

1 / 1 point

'abC'

'ABc'

Correct correct, the method replace returns a copy of the string with all occurrences of the old substring