Python Pop Quiz - Number Explosion - Mouse Vs Python
You will sometimes come across examples of code that use one or two asterisks. Depending on how the asterisks are used, they can mean different things to Python. Check your understanding of what a ...

Source: Mouse Vs Python
You will sometimes come across examples of code that use one or two asterisks. Depending on how the asterisks are used, they can mean different things to Python. Check your understanding of what a single asterisk means in the following quiz! The Quiz What will be the output if you run this code? numbers = range(3) output = {*numbers} print(output) A) {range} B) (range) C) [0, 1, 2] D) (0, 1, 2) E) {0, 1, 2} Hint “Unpacking generalizations” is the term to look up if you get stuck.. The Answer E) {0, 1, 2} Explanation A single asterisk before a Python dictionary or list is known as the unpacking operator. In this example, you tell Python to unpack three integers (0 – 2) into a set. Here is the example running in a REPL: >>> numbers = range(3) >>> output = {*numbers} >>> print(output) {0, 1, 2} >>> print(type(output)) <class 'set'> The code output shows that you have created a set! You can also use a single asterisk to unpack a d