[Solved] What is the utility of the expression “int(a[-1])” in Python?


The expression int(ean8[-1]) takes the last character [-1] of the string ean8 and converts it into an integer to allow further operations, that most require an integer (instead of a string) to be executed.

This is due to the fact that the barcode is present in form of a string, or a sequence of characters. Thats because you can retrieve the last character of a string via index call [-1]. The -1 takes the last element of the list.

solved What is the utility of the expression “int(a[-1])” in Python?