Important built-in functions and keywords in Python

Knowing in detail about built-in functions and keywords in Python

Range

Suppose we want to print the nos. 1–10 present on the list. We would create a list and iterate over it as follows.

An easier way to do it is by using ‘range’. Range takes the arguments: start, stop, step just in the case of slicing. It starts from “start” and goes up to “stop” but not including it. The step is used in case there is a jump needed.

If we need to make a list using range, the following is done.

Enumerate

This code can be written in a simpler way using ‘enumerate’

So ‘enumerate’ keeps track of the index on its own and gives the output as tuples. We can unpack these in the code itself.

Zip

It zips together many lists.

Now let’s add an uneven no. of elements and see the zipping. We can observe that the zipping happens as long as the number of elements is matched. That is it will zip as far as the shortest list goes.

It can be cast into a list too.

In

It helps to check if an element is in an object.

Not in

Min and Max

It helps to return the minimum and maximum value in a list.

Random library

There is a built-in library in python called random. This library has many functions. We need to import the library to be able to use it.

shuffle doesn’t return anything and is an in-place function.

Now let’s try to grab random integers using ‘randint’ function. The randint take two arguments: start and end range

Taking user input

The ‘input’ function helps in taking user input

As observed the output is in the form of a string. But when we need to input numbers, it cannot be in string format but integer format. So we do typecasting.

Refer to the notebook here.

Beginner-level books to refer to learn Python:

Advance-level books to refer to learn Python:

Reach out to me: LinkedIn

Check out my other work: GitHub

Self-driven woman who wishes to deliver creative and engaging ideas and solutions in the field of technology.