Show Menu
Cheatography

Python Functions - Part I Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Built-in Functions

x = str(8) 
print(x)
>>> '8'
print(­typ­e(x))
>>> <class 'str'>
The
str
function accepts an object such as a number and returns a string object.

Defining a Function with Parameter

def Square(x): 
 ­ ­  y = x ** 2
 ­ ­  return y

a = square(5)
print(a)
>>> 25

Docstrings

Docstrings describe what a function does. They are placed in the immediate line after the function header between triple double quotes "­"­".
def Square(x): 
 ­ ­  "­"­" Returns the square of a value"""
 ­ ­  y = x ** 2
 ­ ­  return y