QuestionQ97

Strings

Assuming the following snippet has executed successfully, which expressions evaluate to True?

string = 'REPTILE'[:3:]  
string = string[-1] + string[-2::-1]  
Choose two
  • A len(string) == 3
  • B string[0] == 'E'
  • C string[0] < string[-1]
  • D string is None
Explanation

The resulting value is PER: slicing 'REPTILE' through index 3 produces REP, and the second expression moves its last character to the front while reversing the preceding characters. Therefore its length is 3, and 'P' < 'R' is true in lexicographic character comparison.

Community Discussion

No comments yet. Be the first to start the discussion!