Author Dusty Phillips Reviewers


>>> lst + 2 Traceback (most recent call last)



Download 2,95 Mb.
Pdf ko'rish
bet101/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   97   98   99   100   101   102   103   104   ...   183
Bog'liq
python3-oop

>>> lst + 2
Traceback (most recent call last):
www.it-ebooks.info


Chapter 4
[
 99 
]
File "", line 1, in
TypeError: can only concatenate list (not "int") to list
>>> lst.add
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'list' object has no attribute 'add'
>>> d = {'a': 'hello'}
>>> d['b']
Traceback (most recent call last):
File "", line 1, in
KeyError: 'b'
>>> print(this_is_not_a_var)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'this_is_not_a_var' is not defined
Sometimes these exceptions are indicators of something wrong in our program
(in which case we would go to the indicated line number and fix it), but they also 
occur in legitimate situations. A 
ZeroDivisionError
doesn't always mean we 
received an invalid input. It could also mean we have received a different input.
The user may have entered a zero by mistake, or on purpose, or it may represent
a legitimate value, such as an empty bank account or the age of a newborn child.
You may have noticed all the preceding built-in exceptions end with the name 
Error
. In Python, the words 
error
and 
exception
are used almost interchangeably. 
Errors are sometimes considered more dire than exceptions, but they are dealt with 
in exactly the same way. Indeed, all the error classes in the preceding example have 
Exception
(which extends 
BaseException
) as their superclass.
Raising an exception
We'll get to 
handling exceptions in a minute, but first, let's discover what we should 
do if we're writing a program that needs to inform the user or a calling function 
that the inputs are somehow invalid. Wouldn't it be great if we could use the same 
mechanism that Python uses? Well, we can! Here's a simple class that adds items 
to a list only if they are even numbered integers:
www.it-ebooks.info


Expecting the Unexpected

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   97   98   99   100   101   102   103   104   ...   183




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish