In [ ]:


In [1]:
def myfun():
    print s
s = "this is a python class"
myfun()


this is a python class

In [3]:
def myfun():
    s = "this is python funtions class"
    print s
s = "this is a python class"
myfun()
print s


this is python funtions class
this is a python class

In [4]:
def myfun():
    global s
    s = "this is python funtions class"
    print s
s = "this is a python class"
myfun()
print s


this is python funtions class
this is python funtions class

In [11]:
def myfun():
    #global s
    #print s
    s = "this is python funtions class"
    #print s
s = "this is a python class"
myfun()

In [12]:
s


Out[12]:
'this is a python class'

In [16]:
def myfun(a,b=0):
    print a+b
c = myfun(3)
print c


3
None

In [24]:
def myfun(a,b=3):
    print b
    print b+a
c = myfun(a=5)
print c


3
8
None

In [28]:
def myfun(a,b, *c):
    d=[]
    d.append(a)
    d.append(b)
    [d.append(x) for x in c]
    return d
c = myfun(3,4,5,6,7)
print c


[3, 4, 5, 6, 7]

In [29]:
print myfun


<function myfun at 0x02B6E030>

In [30]:
c  = list

In [31]:
c


Out[31]:
list

In [32]:
c = myfun

In [33]:
for x in c:
    print x


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-33-9888cd81142c> in <module>()
----> 1 for x in c:
      2     print x

TypeError: 'function' object is not iterable

In [36]:
def myfun(a,b, *c):
    d=[]
    d.append(a)
    d.append(b)
    [d.append(x) for x in c]
    return d
c = myfun
print c


<function myfun at 0x02ECE9B0>

In [37]:
for x in c:
    print x


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-9888cd81142c> in <module>()
----> 1 for x in c:
      2     print x

TypeError: 'function' object is not iterable

In [40]:
def myfun(*c, **d):
    print c,d
   
c = myfun(5,6, class1="python", topic="functions")
print c


(5, 6) {'topic': 'functions', 'class1': 'python'}
None

In [ ]: