+ 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

20th May 2017, 5:36 PM
Ghaffaru Mudashiru
Ghaffaru Mudashiru - avatar
10 odpowiedzi
+ 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-JUMP_LINK__&&__python__&&__JUMP_LINK-slicing-strings
30th May 2017, 6:07 AM
David Ashton
David Ashton - avatar
20th May 2017, 8:10 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 10
impressive!
20th May 2017, 8:13 PM
Ghaffaru Mudashiru
Ghaffaru Mudashiru - avatar
+ 8
@David Wow, what a comprehensive explanation 👏😉
30th May 2017, 6:11 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
[::-1] makes the list or a string to be iterated backwards (literally from end to beginning with a step of -1)
30th May 2017, 5:02 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
@Kuba Yeah I got started and couldn't stop. This stuff is addictive! 🙃
30th May 2017, 6:13 AM
David Ashton
David Ashton - avatar
+ 4
Yep, thanks for helping him understand. Wasn't around. [::-1] simply reverses the string
30th May 2017, 8:59 AM
Ghaffaru Mudashiru
Ghaffaru Mudashiru - avatar
+ 3
[::-1])* what's the role of this statement in your coding
24th May 2017, 12:45 AM
Saikiran
Saikiran - avatar
+ 3
sir kuba [::-1])* what is the role of this statement
25th May 2017, 4:02 AM
151289
5th Feb 2020, 5:56 AM
rahul kumar
rahul kumar - avatar