Python3 method of quickly verifying credit card number by Luhn algorithm

Source: Internet
Author: User
In this paper, the method of Python3 to quickly verify credit card number by Luhn algorithm is described. Share to everyone for your reference. The specific analysis is as follows:

Python3 Fast verification of credit card numbers with the Luhn algorithm, Python is cool, simple three lines of code to verify that the credit card number is valid

def luhn_check (num):  ' number-list of reversed digits ' '  digits = [INT (x) for x in reversed (str (num))]  Ch Eck_sum = SUM (digits[::2]) + SUM ((DIG//10 + dig%10) for dig in [2*el for El in Digits[1::2]])  return check_sum%10 = = 0 if __name__ = = "__main__":  print (Luhn_check (543298376))

It is hoped that this article is helpful to everyone's Python3 program design.

  • Related Article

    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.