39.0k views
1 vote
If the variable data refers to the string "No way!", then what does the expression data[-1] evaluate to

User Ddewaele
by
5.0k points

1 Answer

2 votes

Answer:

'!'

Step-by-step explanation:

In python, a string can be traversed from end very easily by using negative indexes, so, if index 0 points to the first element of the string, then, index -1 will point to the last element of the string, that is why, when data[-1] is printed last element of data, which is '!' is printed. Also, it can take more parameters separated by a colon, which are end index and step.

User Sama
by
5.1k points