How to use exception handling in a funcation. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use exception handling in a funcation.

A funcation take one argument as string and convert them in to float, if user put integer in argument then how to use try and except to find error ?

16th Apr 2020, 12:10 PM
Anil Swami
Anil Swami - avatar
1 Answer
+ 3
Anil Swami Do you want to convert string into float? Would you give an example? If it is something like '1.002' then you can simply check the condition as if '.' in string: try: variable = float(string) except: print('error!') else: print('integer detected')
16th Apr 2020, 12:43 PM
Utkarsh Sharma
Utkarsh Sharma - avatar