Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python try else

try:
   # Code to test / execute
   print('Test')
except (SyntaxError, IndexError) as E:  # specific exceptions
   # Code in case of SyntaxError for example
   print('Synthax or index error !')
except:
   # Code for any other exception
   print('Other error !')
else:
   # Code if no exception caught
   print('No error')
finally:
   # Code executed after try block (success) or any exception (ie everytime)
   print('Done')

# This code is out of try / catch bloc
print('Anything else')
Comment

python try else

try:
    a=2*3
except TypeError:
    print("Exception raised")
else:
    print("Everything is ok.")
Comment

Python Try Except Else Clause

# program to print the reciprocal of even numbers

try:
    num = int(input("Enter a number: "))
    assert num % 2 == 0
except:
    print("Not an even number!")
else:
    reciprocal = 1/num
    print(reciprocal)
Comment

PREVIOUS NEXT
Code Example
Python :: query set 
Python :: python try 
Python :: create django app 
Python :: plotly ylog 
Python :: scipy.arange is deprecated and will be removed 
Python :: img not responding jupyter notebook imshow 
Python :: append two dfs 
Python :: how to access app.config globally in flask app 
Python :: pymongo dynamic structure 
Python :: convert pdf to excel python 
Python :: column to list pyspark 
Python :: python print main arguments 
Python :: pandas series create 
Python :: join on index python 
Python :: customize email for djoser activation 
Python :: python __add__ 
Python :: flask sqlalchemy case insensitive like 
Python :: git clone in python to tmp directory 
Python :: pyton como identificar se é numero 
Python :: map in python 
Python :: how to add user input for a question python 
Python :: print(f ) python 
Python :: to_datetime with non zero padded values python 
Python :: what is fn.call 
Python :: tuple methods in python 
Python :: selenium session id python 
Python :: python second element of every tuple in list 
Python :: 151 - Power Crisis solution 
Python :: stdin and stdout python 
Python :: pandas chesk if object is string or tuple 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =