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 :: join function 
Python :: pd merge_asof 
Python :: df dtype 
Python :: trim all new rows string python 
Python :: python - remove exta space in column 
Python :: scan wifi networke micropython 
Python :: Average of total in django querysets 
Python :: cmap perlin noise python 
Python :: pydub create empty track 
Python :: # logging 
Python :: numba for python 
Python :: remove grid in imshow 
Python :: how to get the output in rupees in pandas 
Python :: Access python http.server on google colab 
Python :: generate a random np image array with shape 
Python :: Python __add__ magic method 
Python :: drf serializer unique together 
Python :: threshold meaning in pandas dropna 
Python :: how to redirect where requests library downloads file python 
Python :: stackoverflow: install old version of networkx 
Python :: read excel by row and output to txt 
Python :: print f python 
Python :: how to use with statement in python 2.5 and earlier 
Python :: pandas select only columns with na 
Python :: how to hello world in python 
Python :: plt grid linestyles options 
Python :: python function 
Python :: 151 - Power Crisis 
Python :: exception logging 
Python :: python toupls 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =