0% found this document useful (0 votes)
39 views

CH 3 1 Slides Edx

The document introduces functions in Python. It provides examples of using built-in functions like max() and round() to find the maximum value in a list and round numbers to a specified number of decimal places. It also shows how to use the help() function to view documentation on other functions like round() and their parameters.

Uploaded by

kencasanov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

CH 3 1 Slides Edx

The document introduces functions in Python. It provides examples of using built-in functions like max() and round() to find the maximum value in a list and round numbers to a specified number of decimal places. It also shows how to use the help() function to view documentation on other functions like round() and their parameters.

Uploaded by

kencasanov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

INTRO TO PYTHON FOR DATA SCIENCE

Functions
Intro to Python for Data Science

Functions
Nothing new!
type()
Piece of reusable code
Solves particular task
Call function instead of writing code yourself
Intro to Python for Data Science

Example
In [1]: fam = [1.73, 1.68, 1.71, 1.89]

In [2]: fam
Out[2]: [1.73, 1.68, 1.71, 1.89]

In [3]: max(fam)
Out[3]: 1.89

[1.73, 1.68, 1.71, 1.89] max() 1.89


Intro to Python for Data Science

Example
In [1]: fam = [1.73, 1.68, 1.71, 1.89]

In [2]: fam
Out[2]: [1.73, 1.68, 1.71, 1.89]

In [3]: max(fam)
Out[3]: 1.89

In [4]: tallest = max(fam)

In [5]: tallest
Out[5]: 1.89
Intro to Python for Data Science

round()
In [6]: round(1.68, 1)
Out[6]: 1.7

In [7]: round(1.68)
Out[7]: 2

In [8]: help(round) Open up documentation

Help on built-in function round in module builtins:

round(...)
round(number[, ndigits]) -> number

Round a number to a given precision in decimal digits


(default 0 digits). This returns an int when called with
one argument, otherwise the same type as the number.
ndigits may be negative.
Intro to Python for Data Science

round()
In [8]: help(round)

round(...)
round(number[, ndigits]) -> number

Round a number to a given precision in decimal digits


(default 0 digits). This returns an int when called with
one argument, otherwise the same type as the number.
ndigits may be negative.

round(1.68, 1)
round()
1.68 number

1 ndigits ! 1.7
Intro to Python for Data Science

round()
In [8]: help(round)

round(...)
round(number[, ndigits]) -> number

Round a number to a given precision in decimal digits


(default 0 digits). This returns an int when called with
one argument, otherwise the same type as the number.
ndigits may be negative.

round(1.68)
round()
1.68 number
no input ndigits ! 2
Intro to Python for Data Science

round()
In [8]: help(round)

round(...)
round(number[, ndigits]) -> number

Round a number to a given precision in decimal digits


(default 0 digits). This returns an int when called with
one argument, otherwise the same type as the number.
ndigits may be negative.

round(number)

round(number, ndigits)
Intro to Python for Data Science

Find functions
How to know?
Standard task -> probably function exists!
The internet is your friend
INTRO TO PYTHON FOR DATA SCIENCE

Lets practice!

You might also like