QuestionQ66

VerifiedData Collections – Tuples, Dictionaries, Lists, and Strings

How many elements does the following list have?

data = [i for i in range(-1, 2)]  
Explanation

Python’s range(-1, 2) yields the integers -1, 0, and 1; its ending value is excluded. The list comprehension therefore creates three elements.

Community Discussion

No comments yet. Be the first to start the discussion!