Question | Click to View Answer |
What does the following code return? list(range(5))
|
The |
What does the following code return? list(range(3, 7))
|
The |
What does the following code return? type(range(100))
|
The |
What does the following code return? list(range(100, 300, 50))
|
The |
What does the following code return? list(range(10, 0, -2))
|
Descending ranges can also be constructed. |
What does the following code print? r = [x ** 2 for x in range(5)]
print(r)
|
This code squares all the numbers in This code is an example of a list comprehension. List comprehensions are elegant ways to create lists from other lists. |
What does the following code print? r = [2 ** i for i in range(5)]
print(r)
|
This code raises 2 to all the numbers in This is another example that uses the list comprehension syntax. |
What does the following code print? r = [x for x in range(10) if x % 2 == 0]
print(r)
|
This example uses a list comprehension to make a list with all the even numbers in |
What does the following code print? r = [(x, y) for x in range(2) for y in range(2)]
print(r)
|
This example uses a list comprehension to create a list of tuples. |