Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How does this code find if a string is palindrome

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading