<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        關于python中異常的詳細說明

        來源:懂視網 責編:小采 時間:2020-11-27 14:25:35
        文檔

        關于python中異常的詳細說明

        關于python中異常的詳細說明:每個異常都是一 些類的實例,這些實例可以被引發,并且可以用很多種方法進行捕捉,使得程序可以捉住錯誤并且對其進行處理>>> 1/0 Traceback (most recent call last): File "<pyshell#0>", line 1,
        推薦度:
        導讀關于python中異常的詳細說明:每個異常都是一 些類的實例,這些實例可以被引發,并且可以用很多種方法進行捕捉,使得程序可以捉住錯誤并且對其進行處理>>> 1/0 Traceback (most recent call last): File "<pyshell#0>", line 1,

        每個異常都是一 些類的實例,這些實例可以被引發,并且可以用很多種方法進行捕捉,使得程序可以捉住錯誤并且對其進行處理

        >>> 1/0
        
        Traceback (most recent call last):
         File "<pyshell#0>", line 1, in <module>
         1/0
        ZeropisionError: integer pision or modulo by zero

        異常處理

        捕捉異??梢允褂胻ry/except語句。

        >>> def inputnum():
         x=input('Enter the first number: ')
         y=input('Enter the first number: ')
         try:
         print x/y
         except ZeroDivisionError:
         print "The second number can't be zero"
        
         
        >>> inputnum()
        Enter the first number: 10
        Enter the first number: 0
        The second number can't be zero

        raise 觸發異常

        >>> class Muff:
         muffled=False
         def calc(self,expr):
         try:
         return eval(expr)
         except ZeroDivisionError:
         if self.muffled:
         print 'Division by zero is illegal'
         else:
         raise
        
         
        >>> c=Muff()
        >>> c.calc(10/2)
        
        Traceback (most recent call last):
         File "<pyshell#33>", line 1, in <module>
         c.calc(10/2)
         File "<pyshell#31>", line 5, in calc
         return eval(expr)
        TypeError: eval() arg 1 must be a string or code object
        >>> c.calc('10/2')
        >>> c.calc('1/0')
        
        Traceback (most recent call last):
         File "<pyshell#35>", line 1, in <module>
         c.calc('1/0')
         File "<pyshell#31>", line 5, in calc
         return eval(expr)
         File "<string>", line 1, in <module>
        ZeroDivisionError: integer pision or modulo by zero
        >>> c.muffled=True
        >>> c.calc('1/0')
        Division by zero is illegal

        多種異常類型

        try:
         x=input('Enter the first number:')
         y=input('Enter the seconed number:')
         print x/y
        except ZeroDivisionError:
         print "The second number can't be zero!"
        except TypeError:
         print "That wasn't a number,was it?"

        同時 捕捉多個異常

        try:
         x=input('Enter the first number:')
         y=input('Enter the seconed number:')
         print x/y
        except(ZeroDivisionError,TypeError,NameError):
         print 'Your numbers were bogus...'

        捕捉對象

        try:
         x=input('Enter the first number:')
         y=input('Enter the seconed number:')
         print x/y
        except(ZeroDivisionError,TypeError),e:
         print e
        
         
        Enter the first number:1
        Enter the seconed number:0
        integer pision or modulo by zero

        捕捉所有異常

        try:
         x=input('Enter the first number:')
         y=input('Enter the seconed number:')
         print x/y
        except:
         print 'something wrong happened...'
        
         
        Enter the first number:
        something wrong happened...

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        關于python中異常的詳細說明

        關于python中異常的詳細說明:每個異常都是一 些類的實例,這些實例可以被引發,并且可以用很多種方法進行捕捉,使得程序可以捉住錯誤并且對其進行處理>>> 1/0 Traceback (most recent call last): File "<pyshell#0>", line 1,
        推薦度:
        標簽: 中的 異常 異常的
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲日韩AV一区二区三区四区| 男女拍拍拍免费视频网站| 国产AV日韩A∨亚洲AV电影| 三级网站免费观看| 中文字幕精品亚洲无线码二区 | 亚洲另类自拍丝袜第1页| 99re视频精品全部免费| 久久亚洲AV成人无码电影| 久久午夜羞羞影院免费观看| 亚洲人成电影福利在线播放| 777成影片免费观看| 亚洲色大成网站www永久| 日日麻批免费40分钟日本的| 亚洲人成色7777在线观看| 久久国产乱子伦精品免费一| 久久精品国产亚洲AV麻豆网站| 久久国内免费视频| 色偷偷噜噜噜亚洲男人| 免费国产黄线在线观看| 精品久久久久久亚洲中文字幕| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲高清在线观看| 日韩在线视频免费| 中文字幕一精品亚洲无线一区| 久久久国产精品福利免费| 亚洲另类视频在线观看| 免费国内精品久久久久影院| 中国极品美軳免费观看| 亚洲女久久久噜噜噜熟女| 99re免费99re在线视频手机版| 456亚洲人成影院在线观| 亚洲成av人片不卡无码久久| 亚洲av永久无码天堂网| 亚洲伊人成无码综合网 | 亚洲依依成人亚洲社区| 少妇亚洲免费精品| 亚洲a一级免费视频| 亚洲AV成人一区二区三区观看| 亚洲国产综合无码一区 | 午夜成年女人毛片免费观看| 和老外3p爽粗大免费视频|