In [1]:
def myfun():
    return 10
    return 30
print myfun()


10

In [5]:
f = open('myfile.txt', 'w')
try:  
    f.writes("aasas")
    
    print "I am in try"
except:
    print "in exception"
finally:
    print "I am in finally"
f.close()


in exception
I am in finally

In [6]:
def myfun():
    try:
        return 10
    except:
        return 30
print myfun()


10

In [7]:
def myfun():
    try:
        3/0
        return 10
    except:
        return 30
print myfun()


30

In [16]:
def myfun():
    f = open("myfile.txt", 'w')
    try:

        print "In try"
    except:
        print "in except"
    else:
        print "in else block"
    finally:
        f.close()
        print "in finally"
        return 40
    print "in function"
print myfun()


In try
in else block
in finally
40

In [17]:
help(assert)


  File "<ipython-input-17-57a8227f9ad4>", line 1
    help(assert)
              ^
SyntaxError: invalid syntax

In [21]:
assert 4<3


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-21-0a166cb665c2> in <module>()
----> 1 assert 4<3

AssertionError: 

In [22]:
def addi(a,b):
    return a+b
assert addi(4,3) == 7

In [23]:
def addi(a,b):
    return a+b
assert addi(4,3) != 7


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-23-9e9eba8079cc> in <module>()
      1 def addi(a,b):
      2     return a+b
----> 3 assert addi(4,3) != 7

AssertionError: 

In [24]:
raise


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-9c9a2cba73bf> in <module>()
----> 1 raise

TypeError: exceptions must be old-style classes or derived from BaseException, not NoneType

In [25]:
raise ValueError("this is ,y error")


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-25-74131b8a61ce> in <module>()
----> 1 raise ValueError("this is ,y error")

ValueError: this is ,y error

In [ ]: