Roshan Book

My Tech Notebook

Python tutorial 11- Functions

use pass statement if you want nothing inside function


def testfunc():


You can pass multiple parameters inside python

Once you must pass all parameters when defined

You can also define a default value, for in case all arguments are getting passed

You can also assign value none for parameters, if you don’t want to give default value for parameter.

#To get arbitrary/optional number of arguments

def main():

def testfunc(arg1,arg2, *args):
    print(‘This is a test function’)

if __name__ == “__main__”: main()



args gives other values as tuple

It is immutable. No change, no addition

# passing a named parameters

def main():


def testfunc(**kwargs):

print(‘This is a test function’,kwargs[‘one’])

Kwargs are dictionary and arguments are passing from the caller as dictionary

Sequence of occurrence in a function – Named argument, Arbitary tuple argument and then Keyword arguments

i.e. arg1, arg2, *args, **kwargs

# return values from function

return- loop breaks

yield – that loop breaks and continue from next loop

# Sequence with generator function

Function that generates iterators in function


stop, when only one value

start default value 0

step default value 1


def inclusive_range(*args):


if numargs<1:raise typeError(‘requires at least one argument’)

elif numargs==1





elif numargs==2start=0




elif numargs==3


else: raise Typeerror(“atmax 3 arguments in range function”)


while i<=stop:

yield i



3 responses to “Python tutorial 11- Functions

  1. Discount Replica Handbags December 5, 2011 at 5:09 am

    I always was interested in this topic and stock still am, regards for posting.

  2. replica louis vuitton December 5, 2011 at 5:28 pm

    I do not grant all, but I do congratulate the writer of the blog for the theme.

  3. moncler outlet December 16, 2011 at 6:24 am

    Worth it to read entry, I wait for your next! Thx for share

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: