MENU
Question -

How do you make conversion between tuples and lists ?



Answer -

The function tuple (seq) converts any sequence (actually, any.iterable) into a tuple with the same items in the same order.
For example, tuple([1, 2, 3]) yields (1, 2, 3) and tuple (‘abc’) yields (‘a’, ‘b’, ‘c’). If the argument if a tuple, it does not make a copy but returns the same object, so it is cheap to call tuple( ) when you aren’t sure that an object is already a tuple.
The function list(seq) converts any sequence or iterable into a list with the same items in the same order. For example, list((1, 2, 3)) yields [1, 2, 3] and list (‘abc’) yields [‘a’, ‘b’, ‘c’j. If the argument is a list, if makes a copy just like se[:j would.

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×