this is ugly abuse of list comprehension. The only reason to use list comprehension is to exploit side-effect and turn 2-line loop into one-liner
number = int(input("Enter a number: ")) for number_2 in range(1, 21): print(f"{number} x {number_2} = {number * number_2}")zen of python
(Aug-14-2020, 09:07 AM)spalisetty06 Wrote: It is not yielding a listit's yielding a list, but it's thrown-away, because it's not assigned to a variable. Because print() function will return
None
, it will be list of 20 None
values.number = int(input("Enter a number: ")) foo = [print(f"{number} x {number_2} = {number * number_2}") for number_2 in range(1, 21)] print(foo)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs