Computer Science, asked by dharshukutty28, 17 days ago

Which of the following would give an error? A. list1=[ ]
B. list1=[ ]*3
C. list1=[2,8,7]
D. None of the above

Answers

Answered by Equestriadash
54

(D) None of the above

Let's analyze the options and find out why.

A. list1 = []

This is similar to creating an empty list/assigning an empty list into a variable. There is no issue in doing so, as empty lists can be created by either following the method above or assigning the list data type into the variable like this:

\tt >>>\ list1\ =\ list()

B. list1 = []*3

This command simply repeats the values in the list 3 times. However, since an empty list was given, list1 would still return an empty list. There is no issue in using operators like '+' [along with another list] and '*' for lists.

C. list1 = [2, 8, 7]

This is your regular list assigning. 3 values have been assigned into the variable list1 in the right syntax and hence there will be no error(s).

Since all of the above-mentioned options do not result in errors, the right answer is (D) None of the above.


SachinGupta01: Perfect answer!
Equestriadash: Thank you!
Answered by TheCommander
1

Here we go for a verification! All the given options are correct

Non of these is the answer

Attachments:
Similar questions