Fun Time! Lets see how best you are, in knowing palindromes | Sololearn: Learn to code for FREE!

+13

Fun Time! Lets see how best you are, in knowing palindromes

Input a word to Check. And of course, a like 😝😝 https://code.sololearn.com/c8Q1ERkWlTy1/?ref=app

5/20/2017 5:36:42 PM

Ghaffaru Mudashiru

10 Answers

New Answer

+8

What Kuba said. If Word is "lever", Word[::-1] is "revel". If Word is "level", Word[::-1] is also "level", i.e. Word is a palindrome. The '*' means multiply. You can multiply strings, so: 2 * " not" gives you " not not" 1 * " not" gives you " not" 0 * " not" gives you "" The other thing to remember is that the value of True is 1 and the value of False is 0. a != b is the statement 'a is not equal to b'. if a is a string, e.g. "lever" and b is the same string but backwards, i.e. "revel", then a != b is always True EXCEPT when the word written backwards is the same as the word written forwards, i.e. a palindrome. so if Word = "level", Word != Word[::-1] is False, i.e. 0. 0 * " not" takes the "not" out of the sentence, leaving ..."is a palindrome" if Word = "lever", Word != Word[::-1] is True, i.e. 1. 1 * " not" leaves the "not" in the sentence, giving ..."is not a palindrome" BTW if you want to know more about string slices, you can check out http://pythoncentral.io/how-to-get-a-substring-from-a-string-in-python-slicing-strings

+10

Try using no if ;) https://code.sololearn.com/cR4DVjNP4rXd/?ref=app

+10

impressive!

+8

@David Wow, what a comprehensive explanation 👏😉

+7

[::-1] makes the list or a string to be iterated backwards (literally from end to beginning with a step of -1)

+5

@Kuba Yeah I got started and couldn't stop. This stuff is addictive! 🙃

+4

Yep, thanks for helping him understand. Wasn't around. [::-1] simply reverses the string

+3

[::-1])* what's the role of this statement in your coding

+3

sir kuba [::-1])* what is the role of this statement

0

More examples on Python substring http://net-informations.com/python/basics/substring.htm