0

I was looking at python code that printed palindromes, and I stumbled upon this line of code:

for i in range(1000, 7, -1): if (str(i) == str(i)[::-1])

I'm trying to learn Python right now, and I'm just not that familiar with the syntax. Currently, I understand that this line of code checks to see if the first digit of integer i matches its last digit. Does the syntax of this line mean that the index is being incremented in order to check if it's a palindrome? What is the purpose of having two colons?

estherelle
  • 9
  • 1
  • 3

1 Answers1

1

The colons are separators. Rather than providing a "beginning" and an "end" index, it's telling Python to skip by every -1 objects in the array. It's effectively reversing the array.