Calling Built-In Functions

Built-In Functions

Based on the previous slides, name some functions that we've learned so far

(Remember, a function is a named sequence of statements that performs a specific task or useful operation)

  1. print
  2. type
  3. int
  4. float
  5. str

Using Built-In Functions

How do you use (call) built-in functions in your code? How would you call the function, str, on a value, 300 (that is, convert 300 to a string)?

"""
1. start with the function name, str
2. use parentheses to signify that you're calling a function
3. within those parentheses, put in the value that you're passing in, 300
"""
str(300)

Parentheses after a function name signify that you're calling (executing) that function!

Using Built-In Functions with Multiple Input Values

  1. again start with the function name
  2. use parentheses to signify that you're calling a function
  3. within those parentheses, put in the values, separated by commas, that you're passing in
"""
print can take multiple values as inputs
this contrived example shows two strings as inputs to print
"""

print("Hi ", "there")

Some Terminology

Talkin' the Talk

Using this code as an example:

num = "5"
x = int(num)
  1. what is the name of the function being called?
  2. what are the arguments passed in to the function?
  3. what value is returned from this function call?
  1. int
  2. num, or the string, "5"
  3. the integer, 5

Talkin' the Talk 2

length = 10
width = 7
print(length, width)
  1. what is the name of the function being called?
  2. what are the arguments passed in to the function?
  1. print
  2. the integers, length and width (10 and 7 respectively)

Note that print does not return a value to your program; rather it prints values to the screen.

Composing Functions

t = type(str(5 + 5))
print(t)

What is printed out by this program?

The type of the result of calling str(5 + 5), which turns out to be?

<class 'str'>

A Closer Look At a Built-In Function Called Input