Thursday, August 05, 2021

Day 3 of #30daysofML from Kaggle

Below is my learning for today as part of Day 3 of #30daysofML


help()

help(round)

help(round(-30.18)

help(print)


Defining functions

Builtin functions are great, but we can only get so far with them before we need to start defining our own functions. 

Example if we want to calculate the least difference between 3 numbers

def least_diff (num1, num2, num3):

diff1 =num1-num2

diff2 =num2-num3

diff3 =num3-num1

return min(diff1, diff2, diff3)

Functions start with a header introduced by the def keyword. The indented block of code following the : is run when the function is called.

return is another keyword uniquely associated with functions. When Python encounters a return statement, it exits the function immediately, and passes the value on the right hand side to the calling context.

If there is no return in the function, then the function will not return anything.

But there are some functions with no return statements inside them.  Examples are print() and help()

Python allows trailing commas in argument lists. How nice is that?


No comments:

Free Power BI Classes for Week 7 (Last)

Just completed the last class of the F ree  P ower BI  classes of this series.  Today we have covered Adding a canvas background Adding Imag...