Check If A String Is A Palindrome | Python Example

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ม.ค. 2025

ความคิดเห็น •

  • @fatimawadee4240
    @fatimawadee4240 ปีที่แล้ว +2

    You explained the positional comparison with such clarity - thank you. My Python tutor explained in a manner I failed to understand.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You’re welcome, I’m glad the explanation helped you out! :-)

  • @antonisledziewski5073
    @antonisledziewski5073 ปีที่แล้ว +4

    Clear, simple and substantive explanation. Thanks!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You’re welcome Antoni, I’m glad you found the explanation clear and simple! :-)

  • @folakemiumar6003
    @folakemiumar6003 4 หลายเดือนก่อน

    best so far! Thanks so much for the awesome explanation🙏

  • @Phoenix-lg3mr
    @Phoenix-lg3mr ปีที่แล้ว +2

    Such a clear explanation.. thank you so much dear sir :)

  • @shikshyasharma5327
    @shikshyasharma5327 11 หลายเดือนก่อน

    Thank you, Great Explanation. What about the time complexity ?

  • @herzel1265
    @herzel1265 ปีที่แล้ว

    THANK YOU SO MUCHHH ❤😊 THIS HELPED A LOT

  • @sabuhiasadli6083
    @sabuhiasadli6083 ปีที่แล้ว

    Thank you, was really helpful !

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      You’re welcome, I’m glad it was helpful for you! :-)

  • @danstang12
    @danstang12 ปีที่แล้ว

    this helps, but what about if the input is a phrase or sentence instead? like "never odd or even"

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +2

      This code will work on any string, whether it is a word, or a phrase or sentence. Technically, "never odd or even" is not a palindrome though, because the 5th character is 'r' and the 5th last character is ' ', which don't match. Unless we eliminate the spaces and we get "neverofforeven", but that's sort of a different problem: "is the string in a palindrome if all spaces are removed". And then we need to know whether we are removing things like punctuation marks too, because maybe we only want to consider letters. What you could do in that case is filter the string to get it down to only letters, for example like this: stackoverflow.com/a/12400392. Or maybe only letters and digits, like some of these examples: www.geeksforgeeks.org/python-remove-all-characters-except-letters-and-numbers/. Hopefully this helps Daniel! :-)

    • @danstang12
      @danstang12 ปีที่แล้ว

      @@PortfolioCourses thank you!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      You're welcome! :-)

  • @englishaccentcoach7419
    @englishaccentcoach7419 2 หลายเดือนก่อน

    Thanks from Bangladesh

  • @Akhimed
    @Akhimed 11 หลายเดือนก่อน +1

    Can you just reverse the string using string1[::-1] then check?
    word = str(input(“Enter word: “))
    if word == word[::-1]:
    print(“The word,”, word,” is a palindrome”)
    else:
    print(“The word,”, word,” is not a palindrome”)

    • @anitha.courseera6206
      @anitha.courseera6206 10 หลายเดือนก่อน

      Can you say using functions??? In that simple manner..

  • @abhishekranjan9069
    @abhishekranjan9069 8 หลายเดือนก่อน

    Thank you

  • @bunyodkodirov2120
    @bunyodkodirov2120 ปีที่แล้ว

    Thank you a lot! It was really helpful!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      You're very welcome, I'm glad to hear it was helpful! :-)