functions chapter 4 Flashcards
what is a function?
a function is a named sequence of statements that performs a computation. When you define a function, you specify the name and the sequence of statements. Later, you can “call” the function by name.
Built In Functions
The creators of Python wrote a set of functions to solve common problems and included them in Python for us to use.
The max and min functions give us the largest and smallest values in a list, respectively:
Types of Conversions
The int function takes any value and converts it to an integer, if it can, or complains otherwise:
what are random numbers? or the random module?
The random module provides functions that generate pseudorandom numbers (which I will simply call “random” from here on).
The random function is only one of many functions that handle random numbers. The function randint takes the parameters low and high, and returns an integer between low and high (including both).
Math functions
Python has a math module that provides most of the familiar mathematical functions. Before we can use the module, we have to import it: