Level III

Play with built-in methods

What you have learned so far are functions considered “User-defined functions”, because you, as a user, decide what the function does.  However, there are functions that have been already defined for you, to make your life a bit easier! These are called Built-in functions

For example, if you wish to calculate the minimum or maximum value of a list. You can use the built-in function “min()” and “max()”, respectively. As well as the length of this list, with “len()”. Even if you wanted to sum all the values, you could do it very quickly by only typing “sum()”.

You can also play with strings. Imagine you want to change from uppercase to lowercase style! You just need to use “variable.lower()” where “variable” is the name of the string variable you already declared. And also, the other way around, using “variable.upper()” Let’s see:

Out of curiosity, we will show you other cases  (see list below) in which you can benefit from these built-in methods. Keep in mind that it’s okay to forget them, you do not need to remember them all. As long as you know that built-in methods exist, you can just ask internet whether there is a built-in method that satisfies your needs, and you will get it easy (e.g. “built-in method sum elements”), that is what programmers do all the time!

Built-in methods we like for beginners:

abs()Returns the absolute value of a number.
int()Returns an integer number.
len()Returns the length of an object.
list()Returns a list.
max()Returns the largest item in an iterable.
min()Returns the smallest item in an iterable.
print()Prints to the standard output device.
range()Returns a sequence of numbers, starting from 0 and increments by 1 (by default).
reversed()Returns a reversed iterator.
round()Rounds a numbers.
set()Returns a new set object.
sorted()Returns a sorted list.
str()Returns a string object.
sum()Sums the items of an iterator.
tuple()Returns a tuple.
type()Returns the type of an object.
dictionary.items()Returns the items that are inside of a dictionary: [(‘key’, ‘value’)]. Here “dictionary” corresponds to the name of the variable you selected for the dictionary.

Most of them have been introduced in the previous sections. Here you have some other examples for you to play with.

abs()

It returns the absolute value of a number.

int()

It returns an integer number. For example, here we can convert a float into an int, which is a round number.

reversed()

It returns a reversed iterator, it can be lists, strings, tuples…

dictionary.items()

Returns the items that are inside of a dictionary.