10
def
followed by the name of the functionround()
Use the round() function to get a floating-point number rounded to the specified number of decimals.
Syntax:
The number of digits (ndigits
) is optional, but we will often round number to two decimals:
format()
Here’s how we can do concatenation using the +
operator:
We can do the same with the .format()
method, using {}
as place holders for our variables:
We can use logical expressions in if
statements to return different things from a function: