Skip to main content
The 2024 Developer Survey results are live! See the results
18 events
when toggle format what by license comment
Feb 13, 2023 at 20:21 comment added Karl Knechtel @BenFarmer Yes; Python's dicts are iterable, and iterating over them yields the keys. So it is the same as if .keys() had been called on the dict first.
Feb 13, 2023 at 20:16 history edited Karl Knechtel CC BY-SA 4.0
simplify formatting, depersonalize language, update doc link, fix terminology (argument vs parameter), improve clarity, avoid using builtin name "sum"
Jun 1, 2022 at 3:12 review Suggested edits
Jun 1, 2022 at 9:00
Feb 17, 2019 at 4:06 comment added H.C.Chen The last example implies that * and ** are not only doing the unpacking but also packing! See this excellent page codingame.com/playgrounds/500/…
Sep 15, 2017 at 7:47 comment added Ben Farmer What happens if you (accidentally perhaps :p) unpack a dictionary with only one * instead of two? It seems to do something, it seems like a tuple comes out, but it is not so obvious what it is. (edit: ok I think the answer is that it just unpacks the keys, the values are discarded)
S Aug 28, 2014 at 4:18 history suggested Zero CC BY-SA 3.0
improved 'will execute as' semantics
Aug 28, 2014 at 3:58 review Suggested edits
S Aug 28, 2014 at 4:18
Jul 21, 2014 at 14:38 review Suggested edits
Jul 21, 2014 at 14:39
Mar 8, 2014 at 14:54 comment added user445786 To give some motivation coming from a C background, the * acts in an analogous way as the * operator in C, in that it 'dereferences' the variable. In python context, this means essentially 'removing the outer braces' of arrays or dictionaries.
Nov 20, 2013 at 7:38 comment added IceArdor Here's the real benefit: you can write functions that wouldn't otherwise be possible if you need to have a variable number of arguments. For example, C's printf function, which has 1+n arguments, is tricky to write as an exercise for any beginning programmer. In Python, a beginner can write def printf(string_template, *args) and move on.
Aug 7, 2013 at 15:05 history edited Lasse V. Karlsen CC BY-SA 3.0
fixed incorrect usage of "if neg"
Jul 8, 2013 at 22:24 review Suggested edits
Jul 8, 2013 at 22:45
Dec 11, 2010 at 15:18 history edited Lasse V. Karlsen CC BY-SA 2.5
fixed problem with "neg" option in response to email feedback
May 28, 2010 at 9:18 vote accept psihodelia
May 27, 2010 at 14:29 comment added Lasse V. Karlsen Sure, but then you would have to call it: s = sum((1, 2, 3, 4, 5)) or s = sum([1, 2, 3, 4, 5]), the *values option makes the call look like it takes a number of arguments, but they're packed up into a collection for the function code.
May 27, 2010 at 14:27 comment added Martin Beckett why would you need this, couldn't the function just iterate over the supplied list without it being expanded?
May 27, 2010 at 14:22 history edited Lasse V. Karlsen CC BY-SA 2.5
added 583 characters in body; added 316 characters in body
May 27, 2010 at 14:15 history answered Lasse V. Karlsen CC BY-SA 2.5