The implementation of Python searching for palindrome number

Source: Internet
Author: User

Finding palindrome numbers

Finding palindrome numbers is also a fun topic and a simple application of the filter () function to learn python.

Solution: That is, according to the characteristics of palindrome number can be.

Method 1:1 Line Code resolves

#coding=UTF-8#寻找回文数def is_palindrome(n):       s=str(n)    return s[0:len(s)//2]==s[-1:len(s)//2:-1]    #return str(n)==str(n)[::-1]#测试forin filter(is_palindrome,range(1000)):    print(i)

Method Two: Also a line of code to solve

#coding=UTF-8#寻找回文数def is_palindrome(n):       return str(n)==str(n)[::-1]#测试forin filter(is_palindrome,range(1000)):    print(i)

Learning Python, the more I think of how python can be so powerful, one line of code can solve a lot of problems. The code is so short and short that it's a good point.

           **真心强大**

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The implementation of Python searching for palindrome number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.