We all have our favorite way of intentionally raising an exception in Python. Some like referencing an undefined variable to get a simple NameError, others might import a module that doesn't exist for a bold ImportError.
But the tasteful exceptioneer knows to reach for that classic computer-confounding conundrum: 1/0 for a satisfyingly descriptive DivisionByZero.
So, when does dividing by 0 not raise DivisionByZero?
Why, when you divide 0 by a Decimal(0), of course!
>>> from decimal import Decimal
>>> Decimal(0) / Decimal(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>]
>>> Decimal(1) / Decimal(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
decimal.DivisionByZero: [<class 'decimal.DivisionByZero'>]
The numerator type doesn't seem to matter either:
>>> 0 / Decimal(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>]
"InvalidOperation" just doesn't quite have the same ring to it! Well, they can't all be heroes. :)
You get an undefined error because decimal cannot handle NaNs.
ReplyDeleteIf you do 1 / decimal.Decimal(0) you will get a division by zero error.
I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai
DeleteActually, I'm wrong, the decimal package can handle both infinity and NaN.
ReplyDeletea = decimal.Decimal(float('Inf'))
b = decimal.Decimal(float('NaN'))
The operations are just inconsistent, as seems to be the standard in Python…
https://wiesmann.codiferes.net/wordpress/?p=13366
Help full post, lots of information
ReplyDeletezoho aptitude questions
zoho aptitude questions 2019 pdf
zoho c aptitude questions with answers
c aptitude questions for zoho
zoho aptitude questions with answers
zoho c aptitude questions with answers pdf
zoho aptitude questions 2017 pdf
zoho digital marketing aptitude questions
zoho aptitude questions 2018 pdf
zoho technical support aptitude questions
ReplyDeleteIt is very ideal to see the best subtleties introduced in a simple and getting way. 360DigiTMG project management training
I think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
ReplyDelete360DigiTMG big data analytics courses
He gathers all the necessary facts and information before finding a solution to a problem.
ReplyDeletehttps://360digitmg.com/course/certification-on-robotic-process-automation-rpa
I at long last discovered extraordinary post here.I will get back here. I just added your blog to my bookmark destinations. thanks.Quality presents is the significant on welcome the guests to visit the website page, that is the thing that this page is giving.
ReplyDeletedata scientist course
Thanks for sharing such a great blog......!!!
ReplyDeletefull form
full form of nrc
nrc full form
mbbs full form
full form of rip
Whatsapp Number Call us Now! 01537587949
ReplyDeleteplease visit us: Graphic Design Training
sex video: Dropped phone repair Erie
pone video usa: mobile phone repair in West Des Moines
pone video usa: Social Bookmarking Sites List 2021
Thanks for posting the best information and the blog is very informative.Data science course in Faridabad
ReplyDeleteVery quality post.
ReplyDeletePython Online Training