Show Menu
Cheatography

FUNCTIONS IN PYTHON Cheat Sheet by

This will give wholistic idea about functions in PYTHON

WHY FUNCTIONS?

Repeti­tions (Birthday song)
print(­"­Happy birthday to you!")
print(­"­Happy birthday to you!")
print(­"­Happy birthday to Dear name")
print(­"­Happy birthday to you!")
print(­"­Happy birthday to you!")
print(­"­Happy birthday to you!")
print(­"­Happy birthday to you!")
print(­"­Happy birthday to Dear name")
print(­"­Happy birthday to you!")
print(­"­Happy birthday to you!")

function with argument (custom birthday wishes)

def wishBirthday(name): #passing argument/parameter
    """This function is used to wish birthday to someone""" 
    happy()
    happy()
    print("Happy birthday to you dear",name,'!')
    happy()
wishBirthday("Sourabh")
wishBirthday("Jack")

Function required argument

default arguments in PYTHON

map function in PYTHON

 

Lets define function

def happy():
print(­"­Happy birthday to you!")
:#defi­nition of function

happy() #calling of function
happy()
print(­"­Happy birthday to you dear name")
happy()
happy()
happy()
happy()
print(­"­Happy birthday to you dear name")
happy()
happy()

help/ docume­ntation of function

using . operator
wishBi­rth­day.__­doc__
using help function
help(w­ish­Bir­thday)
 
help(len)

keyword arguments in PYTHON

LAMBDA Function (no name)

 

Multiple functions

def wishSourabh():  
     happy()
     happy()
     print("Happy birthday to dear Sourabh")
     happy()
def wishJack():
     happy()
     happy()
     print("Happy birthday to dear Jack")
     happy()
wishSourabh()
wishJack()

Function can return multiple parameters in PYTHON

Variable Arguments in PYTHON

Global in functions

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Python 3 Cheat Sheet by Finxter

          More Cheat Sheets by sahusourabh

          PYTHON REGULAR EXPRESSION CHEATSHEET Cheat Sheet
          ITERATORS GENERATORS DECORATORS Cheat Sheet