Credit card validity check I want to go more in depth, but this is the 'boilerplate'. 

Is there any way I can optimize this or use more idiomatic Python code?

#Luhn algorithm - distinguish valid numbers from mistyped or incorrect numbers.
def checkNumber(cc_number=''):
    sum_ = 0
    parity = len(cc_number) % 2
    for i, digit in enumerate([int(x) for x in cc_number]):
        if i % 2 == parity:
            digit *= 2
            if digit &gt; 9:
                digit -= 9
        sum_ += digit
    return sum_ % 10 == 0

def main():
    number = input('Input credit card number: ')

    if 12 &lt; len(number) &lt; 17:
        first_two = number[0:2]
        first_four = number[0:4]

        vendor = None
        if number[0] == 4:
            vendor = 'Visa'
        elif number[0] == '5' and '0' &lt; number[1] &lt; '6':
            vendor = 'Mastercard'
        elif number[0] == '6' or first_four == '6011':
            vendor = 'Discover'
        elif first_two in ('36', '38'):
            vendor = "Diners Club"
        elif first_two in ('34', '37'):
            vendor = 'American Express'

        if vendor is not None:
            if checkNumber(number):
                print(f'This is a valid {vendor} credit card!')
            else:
                print(f'This is not a valid {vendor} credit card.')
        else:
            print('Unknown vendor.')
    else:
        print('Sorry, this is not a valid credit card number!')



print(checkNumber('12345'))
Welcome to Code Review. A few basic pointers about programming in python:


Go through the code style guide as documented in PEP-8.
Instead of putting comments, make use of docstrings.
Use test framework for writing a few tests, and use asserts instead of print() for checks and validations.




From the PEP-8 rules:


Convert the comment about Luhn's algortihm into a docstring.
Variables and functions are named using snake_case convention.
No unnecessary blank lines are needed. Keep the code clean and concise.




Your main function can be broken further, into get_provider, valid_card_number and the one your already have check_number. It is completely your choice if you want to raise an exception in case of wrong inputs or whether the functions should return falsy values.

Instead of having an approximately 10 line of code inside if-statement, deal with the else clause first, and return early.

While you didn't actually write the check_number code, I'll just put my views about that as well here.

Using a list comprehension, with the help of % 9 (\$ \mod 9 \$), you can make it quite pythonic. You can then have a sum(&lt;list comprehension&gt;) % 10 == 0 as a one-liner.

sum(digit * 2 % 9 if i % 2 else digit for i, digit in enumerate(map(int, cc_number[::-1]))) % 10 == 0