Built In Functions

You are going to learn a lot about functions later but right now we need to know how to use the functions that Python and other developers have given us. We have already seen the print function which allows us to print messages to the terminal.

Functions are called by specifying the name: func and then putting parentheses after the name: func(). Functions often take arguments which you will put place inside of the parentheses: func(arg1, arg2). Many (but not all) functions return things from them.

string <-- input('message')

Prints out the given message to the terminal and then waits for the user to type in a message and press enter. The message the user typed is returned from the function as a string.

string <-- str(anything)

Takes any data type and converts it to a string.

int <-- int(string)

Takes a string representation of a number ("42") and converts it to an int.

float <-- float(string)

Takes a string representation of a number ("3.14") and converts it to a float.

int <-- len(string)

Finds the length of a string (how many characters) and returns it as an int.

Try collecting some data from the user and then print out a specialized message like "It's a pleasure to meet you {name}"!

Last updated