Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

PythonPr's tweet image. Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

Answer: B) [4, 16] It's like ordinary loop with body: › if x % 2 == 0 — filters for even numbers › x ** 2 squares them and appends to list For beginners: List comprehensions = loops in one line! So common in Python, you'll see them everywhere.

kotov_dev's tweet image. Answer: B) [4, 16]  

It's like ordinary loop with body:  

› if x % 2 == 0 — filters for even numbers 
› x ** 2 squares them and appends to list  

For beginners: List comprehensions = loops in one line! So common in Python, you'll see them everywhere.

Why guess when you can know?


Answer:-(B)[4, 16] x take value from nums using for loop and check condition if x is divisible by 2 then it insert the value in result as square of x.


B. List comprehension with modulo.


Para cada número na lista nums, SE o número for par, ENTÃO inclua o quadrado desse número na nova lista result ou seja B)


output is B) [4, 16]. For More Reference =>>

KumarT00623760's tweet image. output is B) [4, 16].

For More Reference =>>

Our subscription-free VR fitness app PowerBeatsVR is NOW LIVE on the official Meta Quest store!


B Because only 2 and 4 in the list of nums fulfill the condition of x % 2 == 0 of the list comprehensions.


United States 트렌드
Loading...

Something went wrong.


Something went wrong.