#Using the map Function

def square(n):
    return n * n


L = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
map_object = map(square, L) #Get the  of square of each value of list L

print(list(map_object)) #Convert the map object into a list

The map() function applies a given function to each item of an iterable object. It returns an iterator object containing the transformed element as per the given function. 

Syntax:

map(key, iterable)
key A required argument that specifies the function that will be applied to all the elements of the iterable.
iterable The iterable whose each element will be passed to the key function.

The map() function returns a map object containing the return values by the function after being applied to each item of the iterable. The map object is iterable  and can be casted to other collection data types such as list, tuple, set, etc.

For example if we want to turn all the elements of an iterable to integers, we can pass the built-in int function. For example:

M = map(int, [1.0, 2.0, 3.0, 4.0, 5.0])
print(M)
//<map object at 0x000002B19449BD30>
print(list(M))
//[1, 2, 3, 4, 5]

The decision whether to use the map function or  loops  depends on the specific task. Generally speaking, the map function is typically used for simple  operations and transformations, while loops are used for more complex operations. 

The following example illustrates solving a task with loops and solving the same task using map().

#using while loop
L = ['0.1', '0.15', '0.2', '0.25', '0.3']
i = 0
while i< len(L):
   L[i] = float(i)
   i += 1

print(L)
//[0.0, 1.0, 2.0, 3.0, 4.0]

#using for loop
L = ['0.1', '0.15', '0.2', '0.25', '0.3']
for i,v in enumerate(L):
    L[i] = float(v)

print(L)
//[0.1, 0.15, 0.2, 0.25, 0.3]

#using map() function
L = ['0.1', '0.15', '0.2', '0.25', '0.3']
L = list(map(float, L))
print(L)
//[0.1, 0.15, 0.2, 0.25, 0.3]

More Examples: 

list(map(int, ['1', '2', '3', '4', '5', '6']))
//[1, 2, 3, 4, 5, 6]
list(map(len, [[1, 2], [], [3, 4, 5], [1], [7,8]]))
//[2, 0, 3, 1, 2]
list(map(lambda x: x*x, [i for i in range(10)]))
//[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
list(map( lambda name : ' '.join(name), [('John', 'Doe'), ('Jane','Doe'), ('Will', 'Smith')]))
//['John Doe', 'Jane Doe', 'Will Smith']