112k views
6 votes
Which of these is a correct example of the creation of a list in Python? A. names = [“James”, “Omar”, “Hazel”, “Lee”, “Mia”] B. names = (“James”, “Omar”, “Hazel”, “Lee”, “Mia”) C. list[names] = [“James”, “Omar”, “Hazel”, “Lee”, “Mia”] D. list(names) = (“James”, “Omar”, “Hazel”, “Lee”, “Mia”)

User Danbroooks
by
3.6k points

2 Answers

2 votes

Final answer:

The correct example of creating a list in Python is option A, which uses square brackets to define a list. The other options are either to create a tuple or use incorrect syntax for list creation.

Step-by-step explanation:

The correct example of the creation of a list in Python is:

A. names = [“James”, “Omar”, “Hazel”, “Lee”, “Mia”]

This syntax uses square brackets to define a list, which is a mutable, ordered sequence of elements in Python.

Option B creates a tuple, which is an immutable sequence. Option C is incorrect syntax, as lists don't need to be declared in this way. Option D attempts to create a list from a tuple using incorrect syntax; the correct way would be names = list((“James”, “Omar”, “Hazel”, “Lee”, “Mia”)), but even so, it's not the syntax used for simply creating a list.

User Dirk R
by
4.4k points
9 votes

Answer:

A.

The round brackets () are called tuples. Tuples are another way of storing data, and are slightly different from lists.

Lists are changeable.

Tuples are not changeable outside their codeline.

User Stefan Falk
by
4.3k points