Python: try statement in a single line

前端 未结 13 1626
囚心锁ツ
囚心锁ツ 2020-12-01 03:47

Is there a way in python to turn a try/except into a single line?

something like...

b = \'some variable\'
a = c | b #try statement goes here
<         


        
13条回答
  •  孤独总比滥情好
    2020-12-01 04:45

    How about using two lines. is it ok ?

    >>> try: a = 3; b= 0; c = a / b
    ... except : print('not possible'); print('zero division error')
    ...
    not possible
    zero division error
    

提交回复
热议问题