Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
0
0
0
8.1K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: B ([0,1,2]) The code uses a list comprehension [x for x in range(3)] to create a list. The range(3) function in Python generates a sequence of numbers starting from 0 by default, and stopping before the number 3. The sequence generated is 0, 1, and 2.
English
0
0
0
306
Biel Men
Biel Men@BielMenHaha·
@PythonPr Alternative B A list will be created only for the print within the range 0 to 3 (exclusive)
English
0
0
0
98
Zac Nielsen
Zac Nielsen@itszacnielsen·
@PythonPr B [0, 1, 2] Python counts from zero and leaves out the final number.
English
0
0
0
97
Digital Nomad Art
Digital Nomad Art@DigitalNomadArt·
@PythonPr Within the list [] argument x is declared as a variable of range 3. Since range starts at 0 the range would be 0, 1, 2 when printed () .
English
0
0
0
132
Olabanji Emmanuel Oluwaseun
Olabanji Emmanuel Oluwaseun@Little_Dean_11·
@PythonPr The correct answer is B Explanation: The code print([x for x in range(3)]) uses a list comprehension to generate a list of numbers from 0 up to (but not including) 3. So range(3) produces: 0, 1, 2.
English
0
0
0
3
Python Tech
Python Tech@PythonTech43716·
@PythonPr B is right answer. This is the example of list comprension, in this way you can write the python code nore elegant way..
English
0
0
0
5
LucasH Sketch
LucasH Sketch@dibujoslucas·
@PythonPr B: [0,1,2]. Python and its range, always trolling newbies by ghosting the last number. Love that for us.
English
0
0
0
158
Paylaş