Python
What will ...
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
What will the following code return?
l = {i%2 for i in range(10)}
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
{1, 2}
{0, 1, 0, 1, 0, 1, 0, 1, 0, 1}
{0, 1}
Explanation
Provided expression is a set comprehension. It first iterates over numbers from 0 to 9 and calculates the remainder from division by 2 for each of them. Remainders are later collected into a set. Therefore {0, 1} is correct answer
Like
Login in
to like
Comment
Login in
to comment
Share
Tweet
P
ython
Quiz
Login to learn Python
or
Read more about
Python Quizzes
Follow CodeGalaxy
Mobile Beta
Send Feedback
Keep exploring
Python quizzes
What will be printed out as a result of the following code execution / compilati...
What will be printed out as a result of the following code execution / compilati...
What will be printed out as a result of the following code execution / compilati...
What will be printed out as a result of the following code execution / compilati...
int i = Integer.MAX_VALUE + 10; What is th...
What happens after the following code is compiled and run: ...
Sign Up Now
or
Subscribe for future quizzes
Login in to like
Login in to comment