I am really impressed with two online courses one is “Analytics in Python” at edX by ColombiaX and another is “Python for Data Science” at cognitiveclass.ai or (Previously Bigdatauniversity). So i am going to document what ever i will learn about functions in these two courses.

First there are Built-in functions(Ready made for use), such as help() to ask for help, min() to get the minimum value, print() to print an object to the terminal.

x=5
y=7
z=max(x,y) #max is the function. x and y are the arguments
print(z) #print is the function. z is the argument

You can find an overview with more of these functions here.

Built-in Functions
abs() dict() help() min() setattr()
all() dir() hex() next() slice()
any() divmod() id() object() sorted()
ascii() enumerate() input() oct() staticmethod()
bin() eval() int() open() str()
bool() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() __import__()
complex() hasattr() max() round()
delattr() hash() memoryview() set()

 

User-Defined Functions (UDFs), which are functions that users create to help them out; And

You can define functions to provide the required functionality. Here are simple rules to define a function in Python.

  • Functions blocks begin def followed by the function nameand parentheses ().
  • There are input parameters or arguments should be placed within these parentheses.
  • You can also define parameters inside these parentheses.
  • There is a body within every function starts with a colon (:) and is indented.
  • You can also place documentation before the body
  • The statement “return” exits a function, optionally passing back a value

or sometimes don’t return anything

If no return statement, python returns None

def iamlost():
print(‘Yes I am lost in Python World’)
print(‘Are you too’)
h=9
iamlost()

output:-

Yes I am lost in Python World
Are you too

This is the Best Video on Functions in Python i have come across :-