Cheatography
https://cheatography.com
This will give wholistic idea about functions in PYTHON
WHY FUNCTIONS?
Repetitions (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
|
|
Lets define function
def happy():
print("Happy birthday to you!")
:#definition 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/ documentation of function
using . operator |
wishBirthday.__doc__ |
using help function |
help(wishBirthday) |
|
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
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by sahusourabh