filmov
tv
Python Shorts - Function to check if a string is a palindrome or not

Показать описание
#python #problemsolving #palindrome
A quick solution to create a function to check if a string is a palindrome or not. This uses built in Python string slicing.
Code:
#s is the forward string. s[ : : -1] - includes the whole string, starting at the end, in steps of 1 (ie all characters, reading from the end of the string -- ie the reversed string)
s == s[ : : -1]
A quick solution to create a function to check if a string is a palindrome or not. This uses built in Python string slicing.
Code:
#s is the forward string. s[ : : -1] - includes the whole string, starting at the end, in steps of 1 (ie all characters, reading from the end of the string -- ie the reversed string)
s == s[ : : -1]