FUNCTIONS IN PYTHON Cheat Sheet

A Programming › Python cheat sheet in English by sahusourabh

This will give wholistic idea about functions in PYTHON

12,458 views 1,498 downloads 20 Jul 2022 History

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

Function required argument

default arguments in PYTHON

default arguments in PYTHON

map function 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

keyword arguments in PYTHON

LAMBDA Function (no name)

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

Function can return multiple parameters in PYTHON

Variable Arguments in PYTHON

Variable Arguments in PYTHON

Global in functions

Global in functions

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.