output the squares of all the numbers in a list L = [1, 2, 3, 4]? code example
Example 1: python square all numbers in list
def square(list):
return [i ** 2 for i in list]
Example 2: list comprehension with square numbers python
def square(a):
squares = []
for i in a:
squares.append(i**2)
return squares