+ 1

class tuple vs class list

Hi, recently I was making code challange in Python, and I stumbled on this question: def dostuff(P1, *P2): print(type (P2)) dostuff("a", "b", "c", "d") Apparently, the answer is: class 'tuple' How so? I was sure tuple unpacking (eg *P2) return lists In this example it does: P1, *P2 = "a", "b", "c", "d" print(type (P2)) print(P2) ==================== class'"list' ["b", "c", "d"] So my question is, what is going on inside function brackets that it changes type of data

15th Dec 2021, 10:18 AM
Piotr Ś
Piotr Ś - avatar
4 Respostas
18th Dec 2021, 6:47 PM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 1
Jay Matthews oh I see, thank you. Basically what you mean is: there is no unpacking inside parentheses: those are just values, separated by comas? I thought unpacking is the proces of transferring but it's actually proces of returning?
15th Dec 2021, 11:22 AM
Piotr Ś
Piotr Ś - avatar
+ 1
Jay Matthews Oh wow now you just added more questions 😄, seems like I must dive into documentation for it. If you could just tell what to look for?
15th Dec 2021, 11:41 AM
Piotr Ś
Piotr Ś - avatar
0
Jay Matthews thank you for your answer. I accept that it's tuple and if you return it it prints tuple. I'm just curious, why it couldn't be list? As usually when you unpack tuples? It's because lists are mutable or smth? Or just simply everything inside function parentheses changes to tuple, just like with quotation: everything inside quotation changes to string - even if it's integer, float or list?
15th Dec 2021, 11:01 AM
Piotr Ś
Piotr Ś - avatar