返回顶部

收藏

Catch and recover exception

更多
Matrix = {}

Matrix[(2,3,4)] = 88

Matrix[(7,8,9)] = 99

X = 2; Y = 3; Z = 4              # ; separates statements

print Matrix[(X,Y,Z)]

print Matrix

try:
     print Matrix[(2,3,6)]       # try to index
except KeyError:                # catch and recover
     print 0

标签:Python,基础

收藏

0人收藏

支持

0

反对

0

发表评论