ExamGecko
Question list
Search
Search

Question 38 - JN0-223 discussion

Report
Export

You want to make a list in Python to store data.

Which statement is the correct way to accomplish this task?

A.
L = '0, 1, 2, 3, 4, 5'
Answers
A.
L = '0, 1, 2, 3, 4, 5'
B.
L = {0, 1, 2, 3, 4, 5}
Answers
B.
L = {0, 1, 2, 3, 4, 5}
C.
L = [0, 1, 2, 3, 4, 5]
Answers
C.
L = [0, 1, 2, 3, 4, 5]
D.
L = (0, 1, 2, 3, 4, 5)
Answers
D.
L = (0, 1, 2, 3, 4, 5)
Suggested answer: C

Explanation:

In Python, to create a list, you use square brackets []. The correct syntax to create a list containing the numbers 0 through 5 is:

L = [0, 1, 2, 3, 4, 5]

This statement creates a list object that stores the specified integers.

Other options are incorrect:

A defines a string, not a list.

B defines a set, which is an unordered collection with no duplicate elements.

D defines a tuple, which is an immutable sequence, not a list.

Python Official Documentation: Discusses lists, sets, tuples, and their syntaxes.

Python Data Structures Guide: Provides examples of creating and manipulating lists.

asked 18/09/2024
Abdullah Mousa
45 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first