So one of my friend said this code will find whether a string is palindrome or not
This code works but I am not sure about how this works
pls explain me how this code works
here is the code:
Var = 'radar'
if Var == Var[::-1]:
print("palindrome")
else:
print("not palindrome")
>Solution :
Print the 2 Var:
>>> Var
'radar'
>>> Var[::-1]
'radar'
There is no difference but now try with Var = 'hello':
>>> Var
'hello'
>>> Var[::-1]
'olleh'
The second form Var[::-1] reverse the list.