python - Append a tuple to a list - what's the difference between two ways? -
i wrote first "hello world" 4 months ago. since then, have been following coursera python course provided rice university. worked on mini-project involving tuples , lists. there strange adding tuple list me:
a_list = [] a_list.append((1, 2)) # succeed! tuple (1, 2) appended a_list a_list.append(tuple(3, 4)) # error message: valueerror: expecting array or iterable
it's quite confusing me. why specifying tuple appended using "tuple(...)" instead of simple "(...)" cause valueerror
?
btw: used codeskulptor
coding tool used in course
the tuple
function takes 1 argument has iterable
tuple([iterable])
return tuple items same , in same order iterable‘s items.
try making 3,4
iterable either using [3,4]
(a list) or (3,4)
(a tuple)
for example
a_list.append(tuple((3, 4)))
will work
Comments
Post a Comment