Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"TypeError: 'int' object is not subscriptable" in python

def get_hidden_card(credit_number, star_count=4):
    short_credit_number = str(credit_number[12:16])
    return str('*' * star_count + short_credit_number)


print(get_hidden_card(2034399002125581))

As i understand python don’t wanna work because he think that str(credit_number[12:16]) is int type, how can i fix it?

The error is:

    Traceback (most recent call last):
  File "C:\Users\Ivan\PycharmProjects\pythonProject\main.py", line 10, in <module>
    print(get_hidden_card(2034399002125581))
  File "C:\Users\Ivan\PycharmProjects\pythonProject\main.py", line 4, in get_hidden_card
    short_credit_number = str(credit_number[12:16])
TypeError: 'int' object is not subscriptable

Process finished with exit code 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is must solve your issue

def get_hidden_card(credit_number, star_count=4):
        short_credit_number = str(credit_number)[12:16]
        return str('*' * star_count + short_credit_number)
    
    
    print(get_hidden_card(2034399002125581))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading