Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
If you are a python programmer tell me which return is actually returned? :D

def test():
try:
return 'Inside try block'
except:
return 'Inside Exception'
finally:
return 'Finally block'

print test()

#python #try #except #finally
What is the difference between the below exceptions:

try:
// Your code block
except:
// Your exception block

Vs:

try:
// Your code block
except Exception:
// Your exception block

A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to `except BaseException:`).

NOTE: When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause.

A better try & except:

try:
import platform_specific_module
except ImportError:
platform_specific_module = None

#python #PEP8 #try #except #try_except #exception