About the Tutorial



Download 2,85 Mb.
Pdf ko'rish
bet218/234
Sana28.05.2022
Hajmi2,85 Mb.
#614232
1   ...   214   215   216   217   218   219   220   221   ...   234
Bog'liq
python3 tutorial 060821094426

User-Defined Exceptions 
Python also allows you to create your own exceptions by deriving classes from the standard 
built-in exceptions. 
Here is an example related to 
RuntimeError
. Here, a class is created that is subclassed 
from 
RuntimeError
. This is useful when you need to display more specific information when 
an exception is caught. 
In the try block, the user-defined exception is raised and caught in the except block. The 
variable 
e
is used to create an instance of the class 
Networkerror

class Networkerror(RuntimeError): 
def __init__(self, arg): 
self.args = arg 
So once you have defined the above class, you can raise the exception as follows- 
try: 
raise Networkerror("Bad hostname") 
except Networkerror,e: 
print e.args 


Python 3 
333 
Python 3 – Advanced Tutorial 


Python 3 
334 
Python has been an object-oriented language since the time it existed. Due to this
creating and using classes and objects are downright easy. This chapter helps you become 
an expert in using Python's object-oriented programming support. 
If you do not have any previous experience with object-oriented (OO) programming, you 
may want to consult an introductory course on it or at least a tutorial of some sort so that 
you have a grasp of the basic concepts. 
However, here is a small introduction of Object-Oriented Programming (OOP) to help you. 
Overview of OOP Terminology 

Class:
A user-defined prototype for an object that defines a set of attributes that 
characterize any object of the class. The attributes are data members (class 
variables and instance variables) and methods, accessed via dot notation. 

Class variable:
A variable that is shared by all instances of a class. Class variables 
are defined within a class but outside any of the class's methods. Class variables 
are not used as frequently as instance variables are. 


Download 2,85 Mb.

Do'stlaringiz bilan baham:
1   ...   214   215   216   217   218   219   220   221   ...   234




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