<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Python 程序:檢查字符串是否為回文 > 原文: [https://www.programiz.com/python-programming/examples/palindrome](https://www.programiz.com/python-programming/examples/palindrome) #### 在這個程序中。 您將學習檢查字符串是否是回文 要理解此示例,您應該了解以下 [Python 編程](/python-programming "Python tutorial")主題: * [Python `if...else`語句](/python-programming/if-elif-else) * [Python 字符串](/python-programming/string) * [Python 字符串方法](/python-programming/strings-method) * * * 回文是指向前或向后讀取相同的字符串。 例如,`"dad"`在正向或反向上相同。 另一個例子是`'aIbohPhoBiA'`,其字面意思是對回文的一種煩躁的恐懼癥。 ## 源代碼 ```py # Program to check if a string is palindrome or not my_str = 'aIbohPhoBiA' # make it suitable for caseless comparison my_str = my_str.casefold() # reverse the string rev_str = reversed(my_str) # check if the string is equal to its reverse if list(my_str) == list(rev_str): print("The string is a palindrome.") else: print("The string is not a palindrome.") ``` **輸出** ```py The string is a palindrome. ``` **注意**:要測試程序,請在程序中更改`my_str`的值。 在此程序中,我們采用了存儲在`my_str`中的字符串。 使用方法`casefold()`,我們使其適用于無條件的比較。 基本上,此方法返回字符串的小寫版本。 我們使用內置函數`reversed()`反轉字符串。 由于此函數返回反向對象,因此在比較之前,我們使用`list()`函數將它們轉換為列表。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看