0

Sequence unpacking in tuples

Could you please tell me about it with example? And why the * change a tuples into a list?

8th Jan 2025, 4:36 PM
Rouza TN
Rouza TN - avatar
3 odpowiedzi
+ 1
Rouza, sequence unpacking in Python is basically assigning the items within a tuple to multiple variables. You are dismembering the tuple into new variables, while keeping the original intact. This is useful for handling data further. Example: #begin numbers = (1, 2, 3, 4, 5) a, *b, c = numbers #end In this case: a gets the first element, the number 1. c gets the last one, number 5. b collects the middle elements because you used the * operator. B = [2,3,4], then, and is a list. Here's the beauty of it: the * operator collects elements into a list because lists are more flexible. Python understands we will do something with this data (add more numbers, split them, calculate them).
8th Jan 2025, 5:34 PM
FV Silva
FV Silva - avatar
0
Hello dear how are you doing 🙏
9th Jan 2025, 12:38 PM
John werner
John werner - avatar
0
Hi
9th Jan 2025, 12:42 PM
John werner
John werner - avatar