except:
@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2903 / 12833)
Comment utiliser try:
et ʻexcept: ʻest posté.
J'ai essayé.
http://ideone.com/mhkPBd
alist = [ '7of9', 'Janeway', "B'Elanna Torres" ]
position = 5
try:
print(alist[position])
except:
print("Position is out of range")
run
Position is out of range
except exceptiontype as name:
@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2919 / 12833)
J'ai essayé.
http://ideone.com/rhOmZ8
alist = [ '7of9', 'Janeway', "B'Elanna Torres" ]
position = 5
try:
print(alist[position])
except IndexError as err:
print("Position is out of range")
except Exception as other:
print("Something doesn't sit right well.")
run
Position is out of range
Référence: 5. Exceptions intégrées @ Python >> 3.6.1 >> Documentation >> Bibliothèque standard Python
Recommended Posts