• powerfulpython Profile Picture

    Powerful Python @powerfulpython

    2 years ago

    The two most important exceptions in Python There are over 60 exception types built into Python. And honestly, most of them you don't need to know about. But there are two you ought to memorize: TypeError, and ValueError. Both are well demonstrated with int(). int() accepts strings. If you write int("42"), it returns 42. But if you write int("forty two"), it doesn't return anything. Instead, it raises ValueError. ValueError means "I can take this type of data, but not this specific value." int() takes strings, but not all strings. Now, if you write int([42]), that also triggers an exception - raising TypeError. TypeError means "I cannot accept the type of data you are giving me." int() does not accept lists. Internalizing the above benefits you bigtime, in two ways. First, you spend less time in debugging hell. When you see a stack trace using one or the other, you more immediately know what went wrong, and how to fix it. That is Bigtime Benefit Number One. Number Two is more subtle: The code you write becomes more of a joy to work with, by you and others. Because it is more aligned with how Python itself works. When you write code raising TypeError, or ValueError, you do it congruently with how Python raises them. You avoid an 'uncanny alley' effect of mis-using these exceptions every Python coder sees every day. So reasoning about your code becomes smoother and simpler. All of which makes your coding life better. And better for those who work with you, interacting with your code. Which soon or sooner will come right back to benefit you too, in other ways. Something to think about.

    0 0 3 303 2
  • Download Image
    • Privacy
    • Term and Conditions
    • About
    • Contact Us
    • TwStalker is not affiliated with X™. All Rights Reserved. 2024 www.instalker.org

    twitter web viewer x profile viewer bayigram.com instagram takipçi satın al instagram takipçi hilesi twitter takipçi satın al tiktok takipçi satın al tiktok beğeni satın al tiktok izlenme satın al beğeni satın al instagram beğeni satın al youtube abone satın al youtube izlenme satın al sosyalgram takipçi satın al instagram ücretsiz takipçi twitter takipçi satın al tiktok takipçi satın al tiktok beğeni satın al tiktok izlenme satın al beğeni satın al instagram beğeni satın al youtube abone satın al youtube izlenme satın al metin2 metin2 wiki metin2 ep metin2 dragon coins metin2 forum metin2 board popigram instagram takipçi satın al takipçi hilesi twitter takipçi satın al tiktok takipçi satın al tiktok beğeni satın al tiktok izlenme satın al beğeni satın al instagram beğeni satın al youtube abone satın al youtube izlenme satın al buyfans buy instagram followers buy instagram likes buy instagram views buy tiktok followers buy tiktok likes buy tiktok views buy twitter followers buy telegram members Buy Youtube Subscribers Buy Youtube Views Buy Youtube Likes forstalk postegro web postegro x profile viewer